关于 fread 与 fwrite 函数的问题
#include <stdio.h>#include <stdlib.h>
#define SIZE 20
int main()
{
int count,array1[SIZE],array2[SIZE];
FILE *fp;
for(count = 0; count < SIZE; count++)
array1[count] = (2*count);
if((fp = fopen("direct.txt","wb")) == NULL)
{
fprintf(stderr,"Erroring opening file");
exit(1);
}
if(fwrite(array1,sizeof(int),SIZE,fp) != SIZE)
{
fprintf(stderr,"Error writing to file");
exit(1);
}
fclose(fp);
if((fp = fopen("direct.txt","rb")) == NULL)
{
fprintf(stderr,"Erroring opening file");
exit(1);
}
if(fread(array2,sizeof(int),SIZE,fp) != SIZE)
{
fprintf(stderr,"Erroring reading file");
exit(1);
}
fclose(fp);
for(count = 0; count < SIZE;count++)
{
printf("%d\t%d\n",array1[count],array2[count]);//关于\n的有无和输出的不同
}
return 0;
}
如果加上\n输入正确,不加的话就不对,这是什么原因
这是错误的图片