Reputation: 1025
I do not understand why the following code can create the aaa file, but cannot write '1' (the buffer value) into the aaa file.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
int b;
int buf;
FILE *fp;
buf = 1;
a = 5;
b = 6;
fp = fopen("c:\\aaa.txt","wb");
fwrite(&buf, sizeof(int),1,fp);
return 0;
}
Upvotes: 2
Views: 172
Reputation: 1923
call fclose(fp)
or fflush(fp)
to make sure content of file buffer gets flushed to the file.
Upvotes: 6