Я сделал программу, которая помогает в изучении английского языка. У вас есть код ниже, но для моего вопроса вам не нужно читать и понимать, что внутри. Я хочу создать файл .cfg или .ini, который можно открыть с помощью простого блокнота и который позволяет пользователю изменять:
МАКС. Размер (по умолчанию 15)
Значение Sleep (x) (по умолчанию 500)
Я понятия не имею, как я могу создать такой файл конфигурации, который может быть изменен пользователем, связать его с моим кодом c, а затем после запуска program.exe он принимает изменения оттуда. Есть идеи?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <Windows.h>
#define MAX 15 //word max size
struct slowa
{
char pl_word[MAX];
char eng_word[MAX];
};
void menu(void);
int count_lines(FILE*);
void print_array1 (const int[],int); //print 1-dimension array
void swap (int*,int*);
int main ()
{
srand( time( NULL ) );
int i,k,j;
FILE* fp;
fp = fopen ("tekst", "r");
if (!fp)
{
printf ("zjebales"); //"you fucked up"
return -1;
}
const int lines = count_lines(fp);
int tab[lines]= {};
int* temp = (int*)malloc(lines*sizeof(int));
for (j=0; j<lines; j++)
{
temp[j]=j+1;
}
j=lines;
for (i=0; i<lines; i++)
{
k=rand()%j--;
tab[i]=temp[k]-1;
swap(temp+k,temp+j);
}
free(temp);
struct slowa arr[lines];
rewind (fp);
for (i=0; i<lines; i++)
{
fscanf(fp, "%s %s", arr[tab[i]].pl_word, arr[tab[i]].eng_word);
}
fclose(fp);
char text[MAX];
k=0;
system("cls");
menu();
scanf("%d",&j);
system("cls");
char ch;
while ((ch = getchar()) != '\n' && ch != EOF);
switch (j)
{
case 1:
for (i=0; i<lines; i++)
{
printf ("Podaj tlumaczenie:%s\n", arr[i].eng_word); //"Write translation"
//fgets (text, MAX, stdin);
scanf ("%s",text);
if (strcmp(arr[i].pl_word, text) == 0)
{
puts ("DOBRZE!"); //"Correct!"
k++;
}
else puts ("ZLE!"); //"Wrong"
Sleep(500);
system("cls");
}
break;
case 2:
for (i=0; i<lines; i++)
{
printf ("Podaj tlumaczenie:%s\n", arr[i].pl_word); //"Write translation"
scanf ("%s",text);
if (strcmp(arr[i].eng_word, text) == 0)
{
puts ("DOBRZE!"); //Correct!
k++;
}
else puts ("ZLE!"); //Wrong!
Sleep(500);
system("cls");
}
break;
default:
puts ("miales podac 1 lub 2 dzbanie"); //"You should put 1 or 2"
getchar();
return -1;
}
printf ("Odpowiedziales dobrze na %d/%d pytan. ", k, lines); //"You answered correctly k/lines words"
if (k==lines) puts("No dobra cos tam umiesz");
else if(k>(lines/2)&&k<lines) puts ("Mogloby byc lepiej");
else puts ("Wracaj do nauki debilu");
while ((ch = getchar()) != '\n' && ch != EOF);
getchar();
return 0;
}