请问为什么这样在记事本上显示为乱码啊?
void add() /*货物信息输入函数*/
{
struct Info info;
FILE * fp;
char ch;
if((fp=fopen("D:\\我的文件\\我的文件\\1.dat","w")) == NULL)
{
printf("******************\n");
printf("* 不能打开文件! *\n");
printf("******************\n");
getch();
exit(1);
}
else
{
printf("\tnum:");
gets(info.num);
printf("\tname:");
gets(info.name);
printf("\tprice:");
scanf("%d",&info.price);
printf("\tamount:");
scanf("%d",&info.amount);
getchar();
fwrite(&info,sizeof(info),1,fp);
printf("***************************\n");
printf("* 还需要输入吗?(Y/N): *\n");
printf("***************************\n");
ch=getchar();
getchar();
}
if(ch=='Y'||ch=='y')
fclose(fp);
}
文件 编码格式不对, 用utf-8,如果还不行 用 gbk,可以用 notepad++编辑下:
要想txt不乱码,你要往里面写字符串啊,不要写数字