I have another Problem, fscanf() only can read one string even, there is 2 in file, so it just repeat it.
Ex. In file
Name
ID
when I read it.
struct customer {
int id;
char name[100];
};
struct customer custid[100];
int num_cust = 1;
strcpy(custid[num_cust].name, "Name");
num_cust++;
strcpy(custid[num_cust].name, "ID");
When writing:
int i;
for (i = 1; i < 3; i++) {
fprintf(test, "%s\n", custid[i].name);
}
And reading:
for (i = 1; i < 3; i++) {
rewind(test);
fscanf(test, "%s\n", custid[i].name);
printf("%s\n", custid[i].name);
}
The Result:
Name
Name
Process returned 0 (0x0) execution time : 0.007 s
Press any key to continue.
But When I do it with int, you can have 2 different result, which is what I wanted.
is there a fix, or alternative from fscanf(), since it can't read 2 string?
*scanf("%s"), better usefgets()