I am using the following code to open a .dat file and display it. My dat file has something like this:
George Michael 17
Michelle Anderson 35
Britney Lobele 19
This is the code I am using.....
The problem is that the last line in the file is being diplsyed twice, like this:Code:#include <stdio.h> int main() { FILE *file; char first_name[15]; char last_name[15]; int age; if((file = fopen("people.dat", "r")) == NULL) printf("File could not be opened.\n"); else { printf("First Name\tLast Name\tAge\n"); while(!feof(file)) { fscanf(file, "%s%s%i", &first_name, &last_name, &age); printf("%10s%15s%10i\n", first_name, last_name, age); } fclose(file); } return 0; }
George Michael 17
Michelle Anderson 35
Britney Lobele 19
Britney Lobele 19
How can I fix this?
Thanks.




Reply With Quote