想要存一个二维数组到文件中,再在之后的操作中读出来,但是b[1][1]一直给随机数sh...
本帖最后由 空羊羊 于 2020-12-21 18:41 编辑void main(void){
int arr={0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4};
int brr;
FILE *fp;
if((fp=fopen("a.txt","w"))==NULL){
printf("Fail to open the file.\n");
}
fwrite(arr, 25*sizeof(int), 1, fp);
fclose(fp);
if((fp=fopen("a.txt","w"))==NULL){
printf("Fail to open the file.\n");
}
fread(brr, 25*sizeof(int), 1, fp);
fclose(fp);
printf("%d", brr);
}
void main(void)
{
int arr={0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4};
int brr;
FILE *fp;
//修改文件打开方式
if((fp=fopen("a.txt","wb"))==NULL){
printf("Fail to open the file.\n");
}
fwrite(arr, 25*sizeof(int), 1, fp);
fclose(fp);
if((fp=fopen("a.txt","rb"))==NULL){
printf("Fail to open the file.\n");
}
//修改文件打开方式
fread(brr, 25*sizeof(int), 1, fp);
fclose(fp);
printf("%d", brr);
return;
} xieglt 发表于 2020-12-21 18:43
啊对我没注意到后面要换一种方式打开!谢谢!
页:
[1]