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:

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.
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics