Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

File size information in C

Name: Anonymous 2010-05-29 15:30

Hey, /prog/

When you have a pointer to a FILE structure, what's the standard way of determining the size (in bytes) of the open file?

Name: Anonymous 2010-05-29 16:03

Use fseek to position the file pointer at the end of the file, then get the position using ftell and finally use fseek or rewind to position the file pointer back at the start.

ftell returns the offset as a long int, so it may fail on files whose sizes cannot be represented as a long int.

Name: Anonymous 2010-05-29 18:23

>>1
fstat or fseek+ftell.
>>3
Don't be silly. sizeof is for seeing how much storage a concrete variable needs. It's a compile time operator (the value is known at compile time), and thus it wouldn't work for such purposes.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List