I have a question about the following code. I would like to know how the marked places work, I mean what is happening there.
I have a file, called info.dat, with some lines written by another program. This following code displays the contents of the file, and separates each line with a vertical tab.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
FILE *fp;
int main()
{
char data[MAX];
if( (fp = fopen("info.dat", "r")) == NULL )
{
printf("This file does not exist!");
exit(0);
}
else
{
printf("First N: Last N: GPA\n\n");
fgets(data, MAX, fp); /* does it read the whole file??? */
while( !(foef(fp)) )
{
printf("%s\v", data); /* prints one line, how? */
fgets(data, MAX, fp); /* huh? */
}
fclose(fp);
}
return 0;
}
I would appreciate if someone could enlighten me how it works.
Thanks.