Homemade fstat to get file size, always return 0 length.

Posted by Fred on Stack Overflow See other posts from Stack Overflow or by Fred
Published on 2010-03-27T08:26:45Z Indexed on 2010/03/27 8:33 UTC
Read the original article Hit count: 237

Filed under:
|
|

Hello, I am trying to use my own function to get the file size from a file. I'll use this to allocate memory for a data structure to hold the information on the file.

The file size function looks like this:

long fileSize(FILE *fp){
    long start;
    fflush(fp);
    rewind(fp);
    start = ftell(fp);
    return (fseek(fp, 0L, SEEK_END) - start);

}

Any ideas what I'm doing wrong here?

© Stack Overflow or respective owner

Related posts about c

    Related posts about binary