一中文编码问题,printf显示乱码,fprintf显示正常,在线求教
简单代码如下:
#include <stdio.h>
#include <string.h>
int main()
{
FILE *fpLog = NULL;
fpLog = fopen( "test.txt ", "w ");
char ptemp[100] ;
strcpy(ptemp, "\347\216\213\346\226\207\346\230\216 ");
printf( "%s\n ", ptemp);
fprintf(fpLog, "%s ", ptemp);
fflush(fpLog);
fclose(fpLog);
return 0;
}
运行结果为:
printf:
fprintf: 王文明
请教高手这是什么原因?是特别的编码吗?在线等待,等待您的解答,先谢了
[解决办法]
printf乱码是平台不支持中文,换用vc或dev cpp
[解决办法]
默认是GB编码,而你给个utf-8编码,自然乱码.而用记事本打开文件是会自动识别编码的.