I have a file stream open and ready.
How do I access and change a single Byte in the stream such that the change is reflected on the file?
Any suggestions?
#include "stdio.h"
int main(void)
{
FILE* f = fopen("so-data.dat", "r+b"); // Error checking omitted
fseek(f, 5, SEEK_SET);
fwrite("x", 1, 1, f);
fclose(f);
}
FILE* fileHandle = fopen("filename", "r+b"); // r+ if you need char mode
fseek(fileHandle, position_of_byte, SEEK_SET);
fwrite("R" /* the value to replace with */, 1, 1, fileHandle);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With