Ciao ragazzi, devo scrivere un programma che, inserite due date, mi restituisca la differenza in giorni.
Ho provato, ma non capisco il motivo per cui la differenza sia sempre "0".
Potreste dirmi cosa sbaglio?
Il programma è il seguente.
codice:
#include <stdio.h>
#include <time.h>
int main ()
{
system ("color 3f");
static struct tm date1;
static struct tm date2;
time_t a,b;
int d, m, y;
printf ("Enter the start-date: ");
scanf ("%d/%d/%d", &d, &m, &y);
date1.tm_mday = d;
date1.tm_mon = m-1;
date1.tm_year = y - 1900;
printf ("Enter the end-date: ");
scanf ("%d/%d/%d", &d, &m, &y);
date2.tm_mday = d;
date2.tm_mon = m-1;
date2.tm_year = y - 1900;
printf ("The difference between the dates is: %lf days\n", abs(difftime(mktime(&date1), mktime(&date2))/86400));
system ("PAUSE");
}