Bonjour à tous,

Je suis en train de réaliser un petit projet d'agenda en C.
Quelques tests sur certaines fonctions construites m'ammènent à constater un problème.

Voici un premier exemple de code, qui fonctionne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <time.h>
 
#define FMT_DATE "%d/%m/%Y"
 
int main (void)
{
   char s[100];
   struct tm *t_now = NULL;
 
   time_t tmt = time (NULL);
   t_now = localtime (&tmt);
 
   t_now->tm_mon -= 500;
   mktime(t_now);
 
   t_now->tm_mon -= 500;
   mktime(t_now);
 
   strftime (s, sizeof s, "Time = "FMT_DATE, t_now);
   puts(s);
 
   return 0;
}
Résultat:
Nous avons retranché 500 mois, puis à nouveau 500 mois à la date actuelle, et le résultat est bon. Si on essaie de retrancher 1000 mois d'un seul coup (ce qui revient normalement au même) il y a un problème :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <time.h>
 
#define FMT_DATE "%d/%m/%Y"
 
int main (void)
{
   char s[100];
   struct tm *t_now = NULL;
 
   time_t tmt = time (NULL);
   t_now = localtime (&tmt);
 
   t_now->tm_mon -= 1000;
   mktime(t_now);
 
   strftime (s, sizeof s, "Time = "FMT_DATE, t_now);
   puts(s);
 
   return 0;
}
Résultat :
Ici, on obtient un bogue.

Quelqu'un saurait-il m'expliquer le problème ?
Par avance, merci.