I am trying to print out the directory before the date for my program. It’s probably a very obvious solution but I can’t seem to figure out why it keeps printing the directory before the date. I would like the directory to be the last thing printed out, not the date.
struct stat info;
info = file_info(pDirent->d_name);
char *date = ctime(&info.st_mtime);
if (date == NULL)
{
date = "Null";
}
if (is_directory(pDirent->d_name))
{
printf(" %-10s %-15lld ", date, (long long)info.st_size);
printf(BLUE(" %s "), pDirent->d_name);
}
else
{
printf(" %-10s %-15lld ", date, (long long)info.st_size);
printf(GREEN(" %s "), pDirent->d_name);
}
The output I get is:
obj Sat May 18 13:39:20 2024
and the output I want is:
Sat May 18 13:39:20 2024 obj
I have tried to flush stdout and someone else recommended, I’ve also tried putting all the data into one printf statement and putting the directory as the last argument to format, yet it STILL prints the directory before the date and the date ends up being last.