Code:#include<stdio.h>
int main()
{
FILE *fp;
int i[2];
fp=fopen("g:\carr","wb+");
scanf("%d",&i[0]);
scanf("%d",&i[1]);
fwrite(i,sizeof(i),2,fp);
}
Printable View
Code:#include<stdio.h>
int main()
{
FILE *fp;
int i[2];
fp=fopen("g:\carr","wb+");
scanf("%d",&i[0]);
scanf("%d",&i[1]);
fwrite(i,sizeof(i),2,fp);
}
Got it...Sorry.
1) You did not check if fp is NULL.
2) i is a static array, so sizeof(i) is 2*sizeof(int). Your third arg to fwrite is 2, so that would be an "out of bounds" read.
That is one of the reasons, and the other reason is that the file g:\carr was open with another program...
Because the file fails to be opened!
Tim S.
PS "\" needs to be escaped