Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int TraditionalTimeReturn(unsigned long int, char );
- int Analisys(unsigned long int);
- //double ReturnTotalSeconds(int,int,int);
- void ConversorDeTempo(double *);
- int main()
- {
- unsigned long int Imput_hora;
- double HoraConvEmSegundos;
- int hora,minuto,segundo,centesimo;
- do
- {
- printf("Informe as horas no formato: HHMMSSCC: ");
- scanf("%lu",&Imput_hora);
- if(Imput_hora <= 0 || !Analisys(Imput_hora))
- {
- perror("Humm, houve um pequeno erro na entrada da hora.");
- }
- }while(Imput_hora <= 0 || !Analisys(Imput_hora));
- {
- hora = TraditionalTimeReturn(Imput_hora,'h');
- minuto = TraditionalTimeReturn(Imput_hora,'m');
- segundo = TraditionalTimeReturn(Imput_hora,'s');
- centesimo = TraditionalTimeReturn(Imput_hora,'c');
- // HoraConvEmSegundos = ReturnTotalSeconds(hora,minuto,segundo,centesimo);
- HoraConvEmSegundos = centesimo/100 + (minuto*60+segundo+(hora * 3600));
- ConversorDeTempo(&HoraConvEmSegundos);
- }
- printf("Hora em Formato tradicional %d:%d:%d:%d \nHora em convercao decimal %lu",hora,minuto,segundo,centesimo,(unsigned long int)HoraConvEmSegundos);
- return 0;
- }
- int TraditionalTimeReturn(unsigned long int Imput_hora,char contador)
- {
- if(contador =='h')
- {
- return Imput_hora / 1000000;
- }
- else if (contador == 'm')
- {
- Imput_hora /= 10000;
- return Imput_hora % 100;
- }
- else if(contador == 's')
- {
- Imput_hora %= 10000;
- Imput_hora /=100;
- return Imput_hora;
- }
- else if (contador =='c')
- {
- return Imput_hora %=100;
- }
- }
- double ReturnTotalSeconds(int hora, int minuto, int segundos, int centesimos)
- {
- double total;
- total = centesimos / 100;
- hora *= 3600;
- minuto *= 60 + segundos;
- centesimos /= 100;
- total += hora+minuto;
- return total;
- }
- void ConversorDeTempo(double *Output_time)
- {
- *Output_time *= 1.157407407;
- }
- int Analisys(unsigned long int tempo)
- {
- if( (TraditionalTimeReturn(tempo,'c') > 99) || (TraditionalTimeReturn(tempo,'s') > 59) || (TraditionalTimeReturn(tempo,'m') >59) || (TraditionalTimeReturn(tempo,'h') > 24) )
- {
- return 0;
- }
- else
- {
- return 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement