Code:
if (fscanf(file,"%d %s %d\n",&x[i].id,x[i].name,&x[i].mid1) != NULL) {
printf ("%d %s %d\n",x[i].id,x[i].name,x[i].mid1);
// change the above to this:
int i=0;
while((fscanf(file, "%ld %s %d\n",&x[i].id,x[i].name,&x[i].mid1)) == 3) {
printf("%ld %s %d\n",x[i].id,x[i].name,x[i].mid1);
++i;
}
fscanf(), can be quite fussy, but the idea is that it returns the number of items it has scanned and stored into a variable. When it can't get three items, it should have reached the very end of the file.