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

/*从文件中读取服装信息*/
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

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

读取到的数据找不到结束符,只能一直向下查找直到找到为止,你这些数据是怎么存放进去的,应该是你存放时的问题