#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE*fpin,*fpout;
double f=1,d;
char str[]="thisis\nastring",str1[40],str2[256];
fpin=fopen("open.txt","w");
if(!fpin)
{
printf("打开文件失败\n");
return 0;
}
fprintf(fpin,"%s\n%lf",str,f);
fclose(fpin);
fpout=fopen("open.txt","r");
fscanf(fpout,"%s",str1);
fgets(str2,200,fpout);
fscanf(fpout,"%lf",&d);
printf("%s,%s\n%lf",str1,str2,d);
fclose(fpout);
return 0;
}
为什么总读出来乱码?
下面是对应的文件!
#include <stdio.h>