|
-
Oct 8th, 2002, 01:26 AM
#1
Thread Starter
Addicted Member
Bytes
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-
-
Oct 8th, 2002, 04:37 AM
#2
Monday Morning Lunatic
Just read 4 bytes, and there's your int (32-bit, of course...)
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 8th, 2002, 09:10 AM
#3
Thread Starter
Addicted Member
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-
-
Oct 8th, 2002, 10:03 AM
#4
Monday Morning Lunatic
Code:
int i;
fread(&i, sizeof(int), 1, fp);
...I think, been a while since I did C 
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...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 8th, 2002, 10:07 AM
#5
Thread Starter
Addicted Member
Thanks! That works!
-Shell-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|