fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. void timeCheck(int *clock,int *minutes){
  5. int hour ;
  6. int minute ;
  7. time_t end, start;
  8. double diff;
  9.  
  10. start = (time_t)((clock[0] * 60 + clock[1]) * 60) ;
  11. end = (time_t)((minutes[0] * 60 + minutes[1]) * 60) ;
  12.  
  13. if( end < start ){
  14. end += 24 * 60 * 60 ;
  15. }
  16.  
  17. diff = difftime(end, start);
  18.  
  19. hour = (int) diff / 3600;
  20. minute = (int) diff % 3600 / 60;
  21. printf("The difference is %d:%d\n", hour, minute);
  22. }
  23.  
  24. int main(void) {
  25. int hour[] = {22,20};
  26. int minute[] = {5,40};
  27.  
  28. printf("Start time %d:%d\n",hour[0],hour[1]);
  29. printf("Start time %d:%d\n\n",minute[0],minute[1]);
  30.  
  31. timeCheck(hour,minute);
  32. return 0;
  33. }
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
Start time 22:20
Start time 5:40

The difference is 7:20