Advertisement
luciana1237

clock1

Jul 28th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.70 KB | None | 0 0
  1. /********************************/
  2. /* Calendario.C                 */
  3. /* Autor: Luciana Ribeiro       */
  4. /********************************/
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <unistd.h>
  9.  
  10. #define MINUTE 60
  11.  
  12. struct HoursAndDates {
  13.     int Hh,Mm,secunds,date,years,Month;
  14. };
  15.  
  16. typedef struct HoursAndDates info;
  17.  
  18. int main()
  19. {
  20.     info *time_t= (info *) malloc(sizeof(info));
  21.  
  22.     if (time_t == NULL)
  23.     {
  24.         fprintf(stderr,"erro \n");
  25.         exit( 0 );
  26.     }
  27.  
  28.     time_t->Hh = 23;
  29.     time_t->Mm = 59;
  30.     time_t->date = 30;
  31.     time_t->Month = 12;
  32.     time_t->years = 2018;
  33.  
  34.    while(1){
  35.        
  36.         for(time_t->secunds =0; time_t->secunds <= MINUTE; time_t->secunds++){
  37.             sleep( 1 );
  38.  
  39.             printf("\n\tHORA ATUAL: %d : %d : %ds \n",time_t->Hh,time_t->Mm,time_t->secunds);
  40.             printf("\n\t\t[ DATA: %d / %d / %d ] \n",time_t->date,time_t->Month,time_t->years);
  41.            
  42.  
  43.             if (time_t->secunds >= 60){
  44.                 time_t->Mm = time_t->Mm+1;
  45.                 if (time_t->Mm >= 59)
  46.                     time_t->Mm =0;
  47.                     time_t->Hh = time_t->Hh+1;
  48.                     if (time_t->Hh >= 23)
  49.                         time_t->date = time_t->date+1;
  50.                         time_t->Hh =0;
  51.                         if (time_t->date >=30)
  52.                             time_t->Month = time_t->Month+1;
  53.                             time_t->date =01;
  54.                             if(time_t->Month >= 12)
  55.                                 time_t->years = time_t->years+1;
  56.                                 time_t->Month =01;
  57.            }else {
  58.                 continue;
  59.             }
  60.        }
  61.    }
  62.    return 0;
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement