Ciao ragazzi, devo scrivere un programma in C che, inserite due date, mi restituisca la differenza in giorni. Inoltre, devo inserire in un file "input.txt" le due date separate da uno spazio e in un file "ouput.txt" il risultato.
Questo è il codice; potreste dirmi cosa sbaglio?
codice:
#include <stdio.h>
#include <time.h>
int main ()
{
static struct tm date1;
static struct tm date2;
time_t start, end;
double diffsec;
int d, m, y, diffdays, startdate, enddate;
FILE *in, *out;
system ("color 1b");
time (&start);
in = fopen ("input.txt", "r");
out = fopen ("output.txt", "r");
do
{
printf ("Enter the start-date using the slash bar (/): ");
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 using the slash bar (/): ");
scanf ("%d/%d/%d", &d, &m, &y);
date2.tm_mday = d;
date2.tm_mon = m-1;
date2.tm_year = y - 1900;
}
while (mktime(&date2) < mktime(&date1) || d>31 || m>12 || y<1900 || d==0 || m==0);
fscanf (in, "%.f %.f", mktime (&date1), mktime (&date2));
fscanf (out, "%.f", difftime(mktime(&date2), mktime(&date1))/86400);
fclose (in);
fclose (out);
time (&end);
diffsec = difftime (end, start);
printf ("\n");
if (difftime(mktime(&date2), mktime(&date1))/86400 == 1)
printf ("The difference between the dates is %.f day\n", difftime(mktime(&date2), mktime(&date1))/86400);
else
printf ("The difference between the dates is %.f days\n", difftime(mktime(&date2), mktime(&date1))/86400);
printf ("\n");
printf ("Time of execution: %f seconds\n", diffsec);
printf ("\n");
system ("PAUSE");
}