Advertisement
Jonas_3k

/* Conversor de horário @ 24 to 10 */

Feb 3rd, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.32 KB | None | 0 0
  1. #include<stdio.h>
  2. int TraditionalTimeReturn(unsigned long int, char );
  3. int Analisys(unsigned long int);
  4. //double ReturnTotalSeconds(int,int,int);
  5. void ConversorDeTempo(double *);
  6. int main()
  7. {
  8.     unsigned long int Imput_hora;
  9.     double HoraConvEmSegundos;
  10.     int hora,minuto,segundo,centesimo;
  11.     do
  12.     {
  13.         printf("Informe as horas no formato: HHMMSSCC: ");
  14.         scanf("%lu",&Imput_hora);
  15.         if(Imput_hora <= 0 || !Analisys(Imput_hora))
  16.         {
  17.             perror("Humm, houve um pequeno erro na entrada da hora.");
  18.         }
  19.     }while(Imput_hora <= 0 || !Analisys(Imput_hora));
  20.      {
  21.         hora = TraditionalTimeReturn(Imput_hora,'h');
  22.         minuto = TraditionalTimeReturn(Imput_hora,'m');
  23.         segundo = TraditionalTimeReturn(Imput_hora,'s');
  24.         centesimo = TraditionalTimeReturn(Imput_hora,'c');
  25.         // HoraConvEmSegundos = ReturnTotalSeconds(hora,minuto,segundo,centesimo);
  26.         HoraConvEmSegundos = centesimo/100 + (minuto*60+segundo+(hora * 3600));
  27.         ConversorDeTempo(&HoraConvEmSegundos);
  28.      }
  29.  
  30.     printf("Hora em Formato tradicional %d:%d:%d:%d \nHora em convercao decimal %lu",hora,minuto,segundo,centesimo,(unsigned long int)HoraConvEmSegundos);
  31.     return 0;
  32. }
  33.  
  34. int TraditionalTimeReturn(unsigned long int Imput_hora,char contador)
  35. {
  36.     if(contador =='h')
  37.     {
  38.         return Imput_hora / 1000000;
  39.     }
  40.     else if (contador == 'm')
  41.     {
  42.         Imput_hora /= 10000;
  43.         return Imput_hora % 100;
  44.     }
  45.     else if(contador == 's')
  46.     {
  47.         Imput_hora %= 10000;
  48.         Imput_hora /=100;
  49.         return Imput_hora;
  50.     }
  51.     else if (contador =='c')
  52.     {
  53.         return Imput_hora %=100;
  54.     }
  55.  
  56. }
  57.  
  58. double ReturnTotalSeconds(int hora, int minuto, int segundos, int centesimos)
  59. {
  60.     double total;
  61.     total = centesimos / 100;
  62.     hora *= 3600;
  63.     minuto *= 60 + segundos;
  64.     centesimos /= 100;
  65.     total += hora+minuto;
  66.     return total;
  67. }
  68.  
  69. void ConversorDeTempo(double *Output_time)
  70. {
  71.     *Output_time *= 1.157407407;
  72. }
  73.  
  74. int Analisys(unsigned long int tempo)
  75. {
  76.     if( (TraditionalTimeReturn(tempo,'c') > 99) || (TraditionalTimeReturn(tempo,'s') > 59) || (TraditionalTimeReturn(tempo,'m') >59) || (TraditionalTimeReturn(tempo,'h') > 24) )
  77.     {
  78.         return 0;
  79.     }
  80.     else
  81.     {
  82.         return 1;
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement