1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <stdio.h>
#include <time.h>
int main (void)
{
/* -ed-
char *jour[]= {"dimanche", "lundi","mardi","mercredi","jeudi","vendredi","samedi"};
une chaine n'etant pas modifiable, je recommande l'usage du
qualificateur const.
*/
char const *jour[] =
{ "dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi",
"samedi" };
int y, m, d;
/* -ed-
struct tm t;
afin d'eviter les ennuis, il est fortement conseille d'initialiser
tous les champs a 0 de`s la creation de la structure :
*/
struct tm t = { 0 };
time_t tt;
/* 17/04/2003 */
y = 103; /* 2003-1900 */
/*
m = 4;
relire la doc. La numerotation des mois commence a 0.
*/
m = 4 - 1;
d = 17;
t.tm_sec = 0;
t.tm_min = 0;
t.tm_mday = d;
t.tm_mon = m;
t.tm_year = y;
tt = mktime (&t);
t = *localtime (&tt); // ça plante ici
printf ("date : %s %.2d/%.2d/%.4d\n", jour[t.tm_wday], d, m + 1, y + 1900);
return 0;
} |
Partager