求助一C语言文件读入的问题!急~~

来源:百度知道 编辑:UC知道 时间:2024/05/09 12:14:22
struct Book
{ char name[20];
char callno[20];
}

struct Student
{ char name[10];
char stuID[10];
struct Book hold[10];
}stu[200];
就是一个文件,包含学生信息(结构体数组):姓名,学生号,所借书。
所借书又是一个结构体数组,包括书名和编号。
请问怎样把所有的数据读入呢,用fscanf函数。

实在是不知道关于那个嵌套的结构体怎么读入的问题~又很着急~麻烦大家了~只帮我写fscanf的那块语句就行~~谢!

FileInput()
{
int count=0;
FILE *fp;
fp=fopen("studinfo.txt","r");
if(fp==NULL)
{
printf("\n>>>>>Cannot Open the File!\n");
exit(0);
}
while(!feof(fp))
{
int i=0;
fscanf(fp,"%s %s %d",stud[count].stuID,stud[count].name,&stud[count].items);
for(i=0;i<stud[count].items;i++)
fscanf(fp,"%s %s %s",stud[count].bookheld[i].title,stud[count].bookheld[i].callNO,stud[count].bookheld[i].status);
count++;
}
fclose(fp);
return count;
}

用fread吧。读入字节数那里用sizeof(Student)就可以了。