Hallo!
Wie arbeitet printf denn die liste der argumente ab? bei follgedem code wird zwei mal das erste agrument genommen, obwohl zwei verschiedene angegeben sind:
printf("now: %s last access: %s", ctime(&t_now), ctime(&t_file));
Gibt beide male dasselbe datum aus (t_now), die beiden daten unterschiedlich sind!!!
Wenn man aber die ausgabe auf zwei zeilen verteilt:
printf("now: %s", ctime(&t_now));
printf("last access: %s", ctime(&t_file));
ist alles wieder in ordnung (es werden zwei unterschiedliche daten ausgegeben)!
Hier nochmal das ganze programm:
Code:
#include <stdio.h>
#include <time.h>
#include <sys/stat.h>
int main() {
int stat_retval;
char *sf_name = "sayhello.c";
struct stat sf_stat;
time_t t_now, t_file;
stat_retval = stat(sf_name, &sf_stat);
t_file = sf_stat.st_atime;
t_now = time(NULL);
printf("Now: %s last access: %s", ctime(&t_now), ctime(&t_file));
printf("now: %s", ctime(&t_now));
printf("last access: %s", ctime(&t_file));
return(0);
}
Lesezeichen