fread() and fwrite() - not working with gcc
Hello All,
I am trying to use fread and fwrite in my program to be compiled using gcc. I searched several forums but have no clue why neither of fread and fwrite work for me. Although no errors are shown and the fopen works well, reading or writing does not happen. Even a small code that i copied and pasted from a tutorials site on C-file I/O is not working!!
Code:
#include<stdio.h>
int main()
{
FILE *f;
int buf;
f = fopen("aout.txt","wb");
buf = 100;
fwrite(&buf,sizeof(buf),1,f);
fclose(f);
return 0;
}
In the tutorials site, the output file extension was .dat, however since linux doesnt recognize that, i am using .txt. Is this allowed?
Can anyone tell me what am i missing in the code or any package to be installed? I am using Ubuntu 11.04.
Thanks
anand