Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2015
    Messaggi
    18

    Differenza tra due date (C/C++).

    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");
    }

  2. #2
    codice:
    printf ("The difference between the dates is: %.f days\n", difftime(mktime(&date1), mktime(&date2))/86400);
    01010011 01100001 01101101 01110101 01100101 01101100 01100101 01011111 00110111 00110000
    All errors are undocumented features waiting to be discovered.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.