Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include<stdlib.h>
- #include <time.h>
- typedef struct TIME
- {
- int t_hour;
- int t_min;
- int t_sec;
- };
- void t_printf(TIME *t)
- {
- if(t==NULL)
- return;
- printf("%d : ",t->t_hour);
- printf("%d : ",t->t_min);
- printf("%d\n", t->t_sec);
- }
- TIME *t_sub(TIME *t2, TIME *t1)
- {
- TIME *tmp;
- int m_esp, h_espf, s_esp, m_espf;
- m_esp = h_espf = s_esp = m_espf = 0;
- tmp = (TIME *)malloc(sizeof(TIME));
- if( (t2->t_hour < t1->t_hour) || (t2->t_hour == t1->t_hour && t2->t_min < t1->t_min) ||
- (t2->t_hour == t1->t_hour && t2->t_min == t1->t_min && t2->t_sec < t1->t_sec))
- return NULL;
- if(t2->t_min < t1->t_min)
- {
- m_esp = 60;
- h_espf = -1;
- }
- if(t2->t_sec < t1->t_sec)
- {
- s_esp = 60;
- m_espf = -1;
- }
- tmp->t_hour = t2->t_hour - t1->t_hour + h_espf;
- tmp->t_min = t2->t_min - t1->t_min + m_esp + m_espf;
- tmp->t_sec = t2->t_sec - t1->t_sec + s_esp;
- return tmp;
- }
- int main ()
- {
- time_t rawtime;
- struct tm *info;
- char buffer[80];
- TIME * t_pointer;
- TIME * t_pointer2;
- TIME * t_pointer3;
- t_pointer = (TIME *)malloc(sizeof(TIME));
- t_pointer2 = (TIME *)malloc(sizeof(TIME));
- t_pointer3 = (TIME *)malloc(sizeof(TIME));
- t_pointer2->t_hour = 12;
- t_pointer2->t_min = 00;
- t_pointer2->t_sec = 00;
- time( &rawtime );
- info = localtime( &rawtime );
- t_pointer->t_hour = info->tm_hour;
- t_pointer->t_min = info->tm_min;
- t_pointer->t_sec = info->tm_sec;
- //t_printf(t_pointer);
- t_pointer3 = t_sub(t_pointer2, t_pointer);
- t_printf(t_pointer3);
- free(t_pointer);
- free(t_pointer2);
- free(t_pointer3);
- //printf("Current local second: %d\n", info->tm_hour);
- system("pause");
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment