读写文件基础
编译器是DEVC++,代码是小甲鱼课程上的,应该没抄错,为什么写出的文件是乱码,如图#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp1;
FILE *fp2;
int ch;
if((fp1 = fopen("hello.txt","r"))==NULL)
{
printf("文件打开失败!\n");
exit(EXIT_FAILURE);
}
if((fp2 = fopen("FISHC.txt","w"))==NULL)
{
printf("文件打开失败!\n");
exit(EXIT_FAILURE);
}
while(ch=fgetc(fp1)!=EOF)
{
fputc(ch,fp2);
}
fclose(fp1);
fclose(fp2);
return 0;
} 应该是编码错误吧,查一下写入和读取用的什么编码,就是那个ANSI,ASCII,UTF-8,UTF-8 BOM,GBK,GB2312什么的
页:
[1]