/***************************************************************************
* Copyright (C) 2006 by Matteo "netarrow" Tomasulo *
* netarrow@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
/*
Se sta compilando su windows, il comando per pulire
lo schermo è cls.
*/
#ifdef _WIN32
#define CLEAR "cls"
#else
#define CLEAR "clear"
#endif
/*
Struttura che rappresenta la data.
*/
typedef struct Data {
long anno;
long mese;
long giorno;
} Data;
/*
Questa funziona calcola quanti giorni sono passati dal 4000 a.C
alla data immessa.
*/
long getDay(Data data) {
long a, b, giorni_passati;
if(data.mese < 3) {
data.anno -= 1;
data.mese += 12;
}
a = (long) (data.anno / 100);
b = 2 - a + ( (long) (a / 4));
giorni_passati = (long) (365.25*(data.anno + 4716)) + (30.6001*(data.mese + 1)) + data.giorno + b - 1524;
return giorni_passati;
}
int main(int argc, char *argv[])
{
Data arrivo, partenza;
signed long differenza;
system(CLEAR);
printf("Data di partenza: \n\n");
scanf("%d", &partenza.anno);
scanf("%d", &partenza.mese);
scanf("%d", &partenza.giorno);
system(CLEAR);
printf("Data di arrivo: \n\n");
scanf("%d", &arrivo.anno);
scanf("%d", &arrivo.mese);
scanf("%d", &arrivo.giorno);
differenza = getDay(arrivo) - getDay(partenza);
if(differenza == 0) {
printf("%s\n", "La data è la stessa");
/*
Su windows è meglio mettere una pausa per bloccare l'output
*/
#ifdef _WIN32
system("pause");
#endif
return EXIT_SUCCESS;
}
/*
Facciamo controlli sul risultato per adattare il testo da stampare.
*/
printf("%s %d %s\n", abs
(differenza
) == 1 ? differenza
< 0 ? \
"E' passato":"Manca":differenza < 0 ? "Sono passati":"Mancano", abs(differenza), \
abs(differenza) == 1 ? "giorno":"giorni");
/*
Come per il caso di prima, meglio mettere una pausa
*/
#ifdef _WIN32
system("pause");
#endif
return EXIT_SUCCESS;
}