Why fwrite doesn’t work in writing binary mode?

FILE* bfp = fopen("student.dat", "wb"); 
int n = 1452;       
fseek(bfp, 0, SEEK_SET);
fwrite(&n, sizeof(int), 1, bfp);

FILE* rfp = fopen("student.dat", "rb");
int read = 0;
fread(&read, sizeof(read), 1, rfp);
printf("%d", read);

fclose(bfp);
fclose(rfp);
return 0;

Why is it outputting to zero? I tried "w" mode, but it didn't work. How can I enter it?



Read more here: https://stackoverflow.com/questions/66997060/why-fwrite-doesnt-work-in-writing-binary-mode

Content Attribution

This content was originally published by SuJin at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: