I tried your code in my linux machine . there is no problem ,the expected output came correctly .
Code:
#include<stdio.h>
main(int argc,char argv[]){
int i=0;
int arr1[40]={0}; //to write to file
int arr2[40]={0}; //to read from the file
FILE *f;
for(i=0;i<40;i++){
arr1[i]=i+1;
}
f=fopen("1.txt","w+"); //Changed it for linux
fwrite(&arr1,sizeof(int),40,f);
fclose(f);
f=fopen("1.txt","r+");
printf("freads reads %d elements\n",fread(arr2,sizeof(int),40,f));
for(i=0;i<40;i++)
printf("%d ",arr1[i]); // Printing the read elements
fclose(f);
}
I got the following as the output ,
Code:
freads reads 40 elements
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40