怎么在文件结束之前将其中的数据读入结构体数组中?
文件:
1 Tom
2 James
3 Kitty
4 Neal
5 Philip
6 Randy
7 Ritchie
8 Ricky
9 Rick
程序 如下:
#include<conio.h>
#include<stdio.h>
struct reader
{
int cardnum;
char readername[10];
}readers[50000];
main()
{
int i;
FILE *fp;
fp=fopen("readers.txt","r+");
for(i=0;i<9;i++)
{
fscanf(fp,"%d%s",&readers[i].cardnum,&readers[i].readername);
printf("%d %-10s \n",readers[i].cardnum,readers[i].readername);
}
fclose(fp);
getch();
}