w3resource

C Exercises: File modification time


18. Display Last Modification Time

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.

For more Practice: Solve these Related Problems:

  • Write a C program to display the last access time and creation time of a file along with the modification time.
  • Write a C program to compare the last modification times of two files and report which one is more recent.
  • Write a C program to update and display the last modification time of a file after appending new content.
  • Write a C program to monitor a file's modification time continuously and alert the user if it changes.

Go to:


PREV : File Read/Write Variable.
NEXT : Find File Size.

C Programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

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.