关于fread和fwrite,文件读写的问题
程序代码:
#include<stdio.h> #include<stdlib.h> #include<conio.h> #define SIZE 20 int main() { int count,a1[SIZE],a2[SIZE]; FILE *fp; for(count=0;count<SIZE;count++) a1[count]=2*count; if((fp=fopen("direct.txt","wb"))==NULL) { fprintf(stderr,"Error open file."); exit(1); } if(fwrite(a1,sizeof(int),SIZE,fp)!=SIZE) { fprintf(stderr,"Erroe writing to file."); exit(1); } fclose(fp); if((fp=fopen("direct.txt","rb"))==NULL) { fprintf(stderr,"Error open file."); exit(1); } if(fread(a2,sizeof(int),SIZE,fp)!=SIZE) { fprintf(stderr,"Erroe reading to file."); exit(1); } fclose(fp); for(count=0;count<SIZE;count++) printf("%d\t%d\n",a1[count],a2[count]); getch(); return 0; }请大家帮忙看看,程序是输入数据,然后将数据输入文件direct.txt,再从文件direct.txt中读取数据给数组a2[],程序运行后,打开文件direct.txt看到的是乱码
如下写字板:
" $ &
希望大侠给解释一下,谢谢了!