zhuyuyaya
2022-05-16 13:57
采纳率: 100%
浏览 103

关于c语言文件操作乱码的问题

这个是文本存放的内容

img

但是使用我写的函数将它全部输出时候却只显示了2个,有一个是乱码 如图:

img

这里是我写的将文本内容输出的代码:

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);
}

2条回答 默认 最新

相关推荐 更多相似问题