Checking file size returns the same size

Hi all,
I’m writing to the filesystem and want to check the file size using stat method ( )
If the file doesnt exist, it returns the -1, but if it exists it seems to show the same size of the file: 1591.
Code is like this:
success = stat(FILE_NAME, fileStatBuffer); (“File stat success %d”, success);
if (success != -1)
success = (int)(fileStatBuffer->st_size); (“File size %d”, success);

Is it something obvious I’m missing?

What is the declaration for fileStatBuf?

Normally you’d use it like this:

struct stat sb;
success = stat(FILE_NAME, &sb);

Note that the declaration of struct stat is not a *; you need to allocate the actual structure but the use &sb as the parameter because stat takes a pointer to the structure you allocated.

Thank you, @rickkas7
Yeah I think I had the syntax wrong. Working now. Thanks!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.