Program gifted children choreography. Development of children's creative talent in choreography in preparation for competitions. Diagnostic tasks. Artistry

Program gifted children choreography. Development of children's creative talent in choreography in preparation for competitions. Diagnostic tasks. Artistry

Standard POSIX has its own method to get the file size.
Include the sys/stat.h header to use the feature.

abstract

  • Get file statistics using stat(3) .
  • Get the st_size property.

Examples

Note. Size is limited to 4GB. If not Fat32 system Fat32 then use the 64-bit version!

#include #include int main(int argc, char** argv) ( struct stat info; stat(argv, &info); // "st" is an acronym of "stat" printf("%s: size=%ld\n", argv , info.st_size) #include #include int main(int argc, char** argv) ( struct stat64 info; stat64(argv, &info); // "st" is an acronym of "stat" printf("%s: size=%ld\n", argv , info.st_size);

ANSI C (standard)

ANSI C does not provide a direct way to determine the length of a file.
We will have to use our minds. We will now use the search approach!

abstract

  • Find the file to the end using fseek(3) .
  • Get the current position using ftell(3) .

example

#include int main(int argc, char** argv) ( FILE* fp = fopen(argv); int f_size; fseek(fp, 0, SEEK_END); f_size = ftell(fp); rewind(fp); // to back to start again printf("%s: size=%ld", (unsigned long)f_size )

If the stdin file or pipe. POSIX, ANSI C will not work.
Will return 0 if the file is a pipe or standard stdin.

Opinion: You should use standard instead POSIX. Because it has 64 bit support.