Hello everyone!
I got a question, hope someone knows a answer :)
Im using fopen and fgetc to read bytes from a file. How do i read a integer from a file this way? I want to read a header of a file.
Thanks in advance,
-Shell-
Printable View
Hello everyone!
I got a question, hope someone knows a answer :)
Im using fopen and fgetc to read bytes from a file. How do i read a integer from a file this way? I want to read a header of a file.
Thanks in advance,
-Shell-
Just read 4 bytes, and there's your int (32-bit, of course...)
Ah, so its possible. Can you give me an example on how to do this? How to stuff those bytes into one integer i mean, i now.. i'm a newbie ;)
-Shell-
...I think, been a while since I did C :)Code:int i;
fread(&i, sizeof(int), 1, fp);
fread(target, size, count, file), where size is the size of each element, and count is how many you're reading. In this case, you're reading 1 4-byte number.
I assume it's a binary file, right...
Thanks! That works!
-Shell-