PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Determine file size?

Hello!

How do I determine the size of a file in Ansi C? There are just the fread, fopen, fwrite (etc) functions. but no "fsize". How do I do it? Am I forced to switch to the windows function for it? If ANSI C doesn't contain a way to determine filesize then it is just plain silly... ;)

Please help me.

// Fredrik
Something like this?

Code:

long int fsize (char *szFile)
{
FILE *pFile;
long int lPos;

   pFile = fopen(szFile, "rb");
   if (NULL == pFile)
       return (-1);

   fseek(pFile, 0, SEEK_END);

   lPos = ftell(pFile);

   fclose(pFile);

   return (lPos);
}


I've typed this from memory and didn't compile and test it, so don't scream if it doesn't work.  Should get you started though.  It's been a long time since I did anything with ANSI C-runtime functions.  Everything I've done for the last 7 years is in native Win32 code (where there IS a GetFileSize API).