Posted By

cigraphics on 05/04/10


Tagged

clock 24h


Versions (?)

24H Clock in C


 / Published in: C
 

My homework :)) from university

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. #include <time.h>
  5.  
  6. void clock(void);
  7.  
  8. int main(void) {
  9. clock();
  10. return 0;
  11. }
  12.  
  13. void clock(void) {
  14. int s, m, h;
  15.  
  16. system("color F5");
  17.  
  18. time_t rawtime;
  19. struct tm * timeinfo;
  20. char buffer_s [80];
  21. char buffer_m [80];
  22. char buffer_h [80];
  23. time ( &rawtime );
  24. timeinfo = localtime ( &rawtime );
  25. strftime (buffer_s,80,"%S",timeinfo);
  26. strftime (buffer_m,80,"%M",timeinfo);
  27. strftime (buffer_h,80,"%H",timeinfo);
  28.  
  29. s = atoi(buffer_s)+1;
  30. m = atoi(buffer_m);
  31. h = atoi(buffer_h);
  32.  
  33. printf("%d:%d:%d", h,m,s);
  34.  
  35. while ( s < 61 ) {
  36. system("cls");
  37. if ( s == 60 ) {
  38. ++m;
  39. s = 0;
  40. if ( m == 60 ) {
  41. m = 0;
  42. ++h;
  43. if ( h == 24 ) {
  44. h = 0;
  45. }
  46. }
  47. } else {
  48. ++s;
  49. }
  50. printf("%d:%d:%d", h,m,s);
  51. Sleep(1000);
  52. }
  53. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: jnwright23 on June 23, 2010

Cool! Wanted to do this for a long time! Thanks!

http://illuminatedmirror.org

You need to login to post a comment.