I can write bytes to a file using:
int byte=5;//Random byte number.. :P
And it will save a byte(5) to a file, as i wanted it to do.
BUT now how do i read the file and get the number 5 out of it, i've tried something like this:
const int MAX_FILE_SIZE=255;
unsigned char buffer[MAX_FILE_SIZE];
FILE *f = fopen("test.txt", "rb");
n = fread(buffer, MAX_FILE_SIZE, 1, f);
// error opening file
cout << n << endl;
But this just returns the letter, i wan't to be able to do this after i retrieve the byte:
int rs=#;//This will be what i get out from reading the text file with byte(5) in it.
This doesn't actually work though, instead of getting byte(5) out of the file that i saved byte(5) to, i just get some stange looking letter (obviously thats what byte(5) looks like in a string)
My main question is, how can i get the byte ID from a single character out of a text document :P
Or am i doing this completely wrong?? :)
Last edited on
The opposite of fputc is fgetc.
Topic archived. No new replies allowed.