karthikbalaguru said:
It looks like this function is only available to Unix systems.
I think, you can check with the man page of stat.
Wrong, it is available on a lot of non-Unix systems: cygwin, Windows (albeit
renamed to _stat)
That code looks pretty old and bogus
#include <sys/stat.h> /* declare the 'stat' structure */
These are possibly also needed:
#include <sys/types.h>
#include said:
struct stat stat_p; /* 'stat_p' is a pointer to a structure
* of type 'stat'. */
wrong, stat_p is a struct with an utterly misleading name
if ( -1 == stat (filename, &stat_p))
This style looks childish to me.
{
printf(" Error occoured attempting to stat %s\n", filename);
More typos, plus errors should go to stderr.
Better exit with EXIT_FAILURE if this is an error
}
printf("File size is %d bytes\n", stat_p.st_size);
stat_p.st_size is not an int.
It is an off_t: possibly a long or a long long.
It would be safer to write:
printf("File size is %lld bytes\n", (long long)stat_p.st_size);
Your post was off topic, and a correct answer had already been given with an
appropriate newsgroup to query.
To make things worse, your anwser is misleading and erroneous.
Please refrain from posting answers on topics you do not master, especially
when the question is off topic already.