这个是文本存放的内容
但是使用我写的函数将它全部输出时候却只显示了2个,有一个是乱码 如图:
这里是我写的将文本内容输出的代码:
void xianshi(){
FILE *fp;
struct all *p;
p = (struct all*)malloc(sizeof (struct all));
if((fp = fopen("quanbu.txt","r+")) == NULL){
printf("can not open file!");
exit(1);
}
while(fscanf(fp,"%s %s %s %d %d\n",p->category,p->number,p->bookname,&p->out,&p->noout) != EOF){
p = (struct all*)malloc(sizeof (struct all));
p->next = phead ->next;
phead ->next = p;
}
phead = phead ->next;
printf( "%s\t%s\t%s\t%s\t%s\n","图书类别","书号","书名","已借出数量","未借出数量");
while(phead){
printf("%s\t%s\t%s\t%d\t%d\n",phead->category,phead->number,phead->bookname,phead->out,phead->noout);
phead = phead -> next;
}
fclose(fp);
freed(p);
}