c语言 从文件读取数据到链表中,输出的时候总会多出一行不明的数据
structstudent*readBinaryCreate(char*filename){FILE*fp=fopen(filename,"rb");if(fp==NUL...
struct student * readBinaryCreate(char *filename){ FILE *fp=fopen(filename,"rb"); if(fp==NULL) return NULL; struct student *head,*p,*q; p=(struct student *)malloc(sizeof(struct student)); fread(p,sizeof(struct student),1,fp); if(p!=NULL) { printf("读取成功\n"); head=p; } while(!feof(fp)) { q=(struct student *)malloc(sizeof(struct student)); p->next=q; q->next=NULL; fread(q,sizeof(struct student),1,fp); p=q; } fclose(fp); return head;};这是我写的读取函数,运行的编译器是codeblocks 是我哪里写错了么?
展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询