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.



Follow us on Facebook and Twitter for latest update.