Reputation: 65
I have a file with one line of text that contains data for 4 students and I'm trying to scan a certain number of characters at a time until I reach the end of file and print all the data into a new file and arrange it properly. Here is the text inside the file:
BaruchComp078045MichalMech090060PinhasElek100090YaelitComp080100DorotiMech100100
Here's the function:
void StudAverage(FILE *in, FILE *out)
{
char name[7], faculty[5], mark1[4], mark2[4], Avg[5];
float average;
while (fscanf(in, "%6s%4s%3s%3s", name, faculty, mark1, mark2) != EOF);
{
average = (atof(mark1) + atof(mark2)) / 2;
itoa(average, Avg, 10);
fprintf(out, "%s %s\n", name, Avg);
}
}
The problem is that it only scans the data of the last student and skips all the ones before it. Can someone tell me what I'm doing wrong?
Upvotes: 0
Views: 53
Reputation: 43331
while (fscanf(in, "%6s%4s%3s%3s", name, faculty, mark1, mark2) != EOF)
Remove ;
in the end.
Upvotes: 3