2

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

Jose A
  • 31
  • 6
  • Did you ever figure this out? Seems to still be the same issue now. Thanks. – Gary Nov 28 '20 at 07:06
  • It doesn't appear that the cause of the issue is the same, but I came here first in searching for answer to similar results and got an answer here https://stackoverflow.com/questions/65047611/ctime-functions-in-c-returns-same-string-for-differing-values-of-atime-mtime-a. Of course, the problem was my own stupditiy but it may be helpful to someone. – Gary Nov 29 '20 at 03:26

0 Answers0