okay. I know this function is wrong, but I have an example where the code doesn't exectute as it should when I leave it out. I'm afraid the code is commented in german, sa are the variables.
Basically what it does is read in 3 sets of two strings and a number into a struct, and then write the values to a file.
Now after reading the values to the struct there is an fflush(stdin). If I leave it out, on the second(/3) time writing to the struct, it only asks fo rthe second string.
I'm using gets to read the strings into the struct and fprintf to write to the file. Any ideas?..
I won't add all the code cos I'm pretty sure the problem lies in the following segment, however if somebody want's to see the problem themselves, just say and I'll put up the whole program. It's relatively short anyway...
Code:
int readin()
{
printf("Name: ");
gets(aktuell->name);
printf("Vorname: ");
gets(aktuell->vorname);
printf("PLZ: ");
scanf("%d",&aktuell->PLZ);
fflush(stdin);
fprintf(fp, "%20s %20s %5d", aktuell->name, aktuell->vorname, aktuell->PLZ);
WITH the fflush(stdin) the Program reads:
Code:
Name: (I enter xxx)
Vorname: xxx
PLZ: (I enter yyy cos it's a number)
Name: xxx
Vorname: xxx
PLZ: yyy
Name: xxx
Vorname: xxx
PLZ: yyy
AND WITHOUT:
Code:
Name: xxx
Vorname: xxx
PLZ: yyy
Name: Vorname: xxx
PLZ: yyy
Name: Vorname: xxx
PLZ: yyy
the output on the first is right, the second returns nothing on the last two Name's...
Many thanks in advance,..
~mako
€DIT: Please don't link me to the FAQ, I've read th epart on fflush(stdin) and it doesn't answer why it works here and doesn't without...
And I don't think it's compiler related here either. If you don't believe me, ask for the full program and try executing yourself... Thx again...