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); }
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.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
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