kepler 452b. 2021-12-31 20:05 采纳率: 0%
浏览 36

为什么读文件会出现乱码?

/*从文件中读取服装信息*/
int ReadformFile()
{
    CLOTHING clothe[20];
    FILE *fp;
    int i = 0;
    
    if((fp=fopen("D:\\clothing.txt","r"))==NULL)
    {
        printf("Can't open this file.\n");
        exit(0);
    }

    while(fscanf(fp, "%ld%s%d%d%d%f%d", &clothe[i].num, clothe[i].name, &clothe[i].year,&clothe[i].month,&clothe[i].day,&clothe[i].price,&clothe[i].amount)!=EOF)
        i++;
    fclose(fp);
    return i;
}



img

  • 写回答

2条回答 默认 最新

  • CSDN专家-link 2021-12-31 20:24
    关注

    打开你这个文本文件看看是什麽样子的。使用fprintf还是fwrite写入文件的呢?

    评论

报告相同问题?

问题事件

  • 修改了问题 12月31日
  • 修改了问题 12月31日
  • 创建了问题 12月31日