问题
So, I'm supposed to print the date of access of directories, modification and creation, but they all seem to be the same date. Here's my code:
struct* tm date;
struct stat fileStat;
if(options[0] == 1 && options[1] == 0 && options[2] == 0 && options[3] == 0){
date = localtime(&(fileStat.st_mtime));
printf("M%02i/%d/%i-%02d:%02d", date->tm_mon,date->tm_mday, (date->tm_year + 1900)%100, date->tm_hour,date->tm_min);
date = NULL;
} else if(options[0] == 1 && options[1] == 1 && options[2] == 0 && options[3] == 0){
date = localtime(&(fileStat.st_atime));
printf("A%02i/%d/%i-%02d:%02d", date->tm_mon,date->tm_mday, (date->tm_year + 1900)%100, date->tm_hour,date->tm_min);
date = NULL;
} else if(options[0] == 1 && options[1] == 0 && options[2] == 1 && options[3] == 0){
date = localtime(&(fileStat.st_ctime));
printf("C%02i/%d/%i-%02d:%02d", date->tm_mon,date->tm_mday, (date->tm_year + 1900)%100, date->tm_hour,date->tm_min);
}
The option stuff is just to select between which one I want to print. Would really appreciate some help on this! Thanks
来源:https://stackoverflow.com/questions/44015747/same-date-when-printing-from-st-mtime-st-ctime-st-atime