读取文件的问题
做的是一个学生成绩管理系统(链表做的) 读取文件的函数老是通不过 恳请高手帮改一下 明天就要检查了 急呀程序代码:
void fileread(struct student *head) //定义读取文件函数 { FILE *fp; struct student *pC; if((fp=fopen("record.txt","r+"))==NULL) { printf("文件打开错误!"); return 0; } pC = (struct student*)malloc(LEN); pC = head; fscanf(fp,"%d %d %s %d %d %d %d %d %d %d %d %d %d\n",&pC->num,&pC->Class,pC->name,&pC->finish[0],&pC->finish[1],&pC->finish[2],&pC->finish[3],&pC->finish[4],&pC->finish[5],&pC->finish[6],&pC->finish[7],&pC->finish[8],&pC->finish[9]); pC=pC->next; while(pC!=NULL) { pC = (struct student*)malloc(LEN); fscanf(fp,"%d %d %s %d %d %d %d %d %d %d %d %d %d\n",&pC->num,&pC->Class,pC->name,&pC->finish[0],&pC->finish[1],&pC->finish[2],&pC->finish[3],&pC->finish[4],&pC->finish[5],&pC->finish[6],&pC->finish[7],&pC->finish[8],&pC->finish[9]); pC=pC->next;; } fclose(fp); } void filesave(struct student *head) { FILE *fp; struct student *pC = head; if((fp=fopen("record.txt","w+"))==NULL) { printf("文件打开错误!"); exit(0); } if(pC==NULL) printf("error"); else { while(pC!=NULL) { fprintf(fp,"%d %d %s %d %d %d %d %d %d %d %d %d %d\n",pC->num,pC->Class,pC->name,pC->finish[0],pC->finish[1],pC->finish[2],pC->finish[3],pC->finish[4],pC->finish[5],pC->finish[6],pC->finish[7],pC->finish[8],pC->finish[9]); pC=pC->next; } } fclose(fp); }