From the course: C: Data Structures, Pointers, and File Systems

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Getting file information

Getting file information - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

Getting file information

- To gather information about a file, it's type, size, timestamps, and other trivia, you use the stat() function. This function is prototyped in the sys/stat header file which is included in this exercise file at line two. The stat() function requires two arguments as shown on line 10. A filename string, and I'm using alpha.txt which is included with the exercise files and it's declared as a string constant at line seven. The second argument to the stat() function is the address of a stat() structure, fstat here, which is declared at line eight. Two stat() structure members are accessed for output. The first printf statement at line 11 access the st_size member which lists the file size. The second printf statement at line 15 accesses the st_mtime member which contains a clock tick value representing when the file was last modified. Here at line 15, I'm using the ctime function to convert the clock tick value into a displayable string. Build and run. And you see that the stat()…

Contents