Advertisement
nirzon

Time struct

Sep 2nd, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<windows.h>
  3. struct time_struct{
  4. int hour;
  5. int min;
  6. int sec;
  7. };
  8. struct time_struct setTime(struct time_struct newTime);
  9. void dispalyTime(struct time_struct dis);
  10. void delay();
  11. struct time_struct update(struct time_struct up);
  12. int main(){
  13. struct time_struct clock={0,0,0};
  14. // clock=setTime(clock);
  15. while(1){
  16. delay();
  17. clock=update(clock);
  18.  
  19. if(clock.min==3) break;
  20.  
  21.  
  22. }
  23.  
  24.  
  25. dispalyTime(clock);
  26.  
  27. return 0;
  28. }
  29. struct time_struct setTime(struct time_struct newTime){
  30. printf("Set time :");
  31. scanf("%d %d %d",& newTime.hour,&newTime.min,&newTime.sec);
  32. return newTime;
  33. }
  34.  
  35. void dispalyTime(struct time_struct dis){
  36. printf("%d:%d:%d\n",dis.hour,dis.min,dis.sec);
  37. }
  38.  
  39. void delay(){
  40.  
  41. Sleep(1000);
  42.  
  43. }
  44.  
  45. struct time_struct update(struct time_struct up){
  46. up.sec +=1;
  47. if(up.sec==60){
  48. up.min+=1;
  49. up.sec=0;
  50. dispalyTime(up);
  51. if(up.min==60){
  52. up.hour+=1;
  53. up.min=0;
  54.  
  55. if(up.hour==24)
  56. up.hour=0;
  57.  
  58. }
  59. }
  60. return up;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement