w3resource

C Exercises: File modification time

C File Handling : Exercise-18 with Solution

Write a program in C to display the last modification time of a file.

Test Data:
Last date of File modification: Sat Nov 26 17:32:15 2022

Sample Solution:

C Code:

#include <time.h>
#include <sys\stat.h>
#include <stdio.h>
int main(){
    struct stat status;
    FILE *fp;
    fp=fopen("i.txt","r");
    fstat(fileno(fp),&status);
    printf("Last date of File modification : %s",ctime(&status.st_ctime));
    return 0;
}

Sample Output:

Last date of File modification: Sat Nov 26 17:32:15 2022

Note: This code run on Dev-C++ 5.11

Flowchart:

Flowchart: File modification time.

C Programming Code Editor:

Previous: File read and write using variable.

Next: Write a program in C to decrypt a previously encrypted file file.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/c-programming-exercises/file-handling/c-file-handling-exercise-18.php