public
Created

Mostra um relógio por software

  • Download Gist
gistfile1.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
/* Mostra um relógio por software */
#include <stdio.h>
 
#define DELAY 1280000
 
struct my_time {
int hours;
int minutes;
int seconds;
};
 
void display(struct my_time *t);
void update(struct my_time *t);
void delay(void);
 
main(void) {
struct my_time systime;
systime.hours = 0;
systime.minutes = 0;
systime.seconds = 0;
 
for (;;) {
update(&systime);
display(&systime);
}
}
 
void update(struct my_time *t) {
t->seconds++;
 
if (t->seconds == 60) {
t->seconds = 0;
t->minutes++;
}
 
if (t->minutes == 60) {
t->minutes = 0;
t->hours++;
}
 
if (t->hours == 24) t->hours = 0;
delay();
}
 
void display(struct my_time *t) {
printf("%02d:%02d:%02d\n", t->hours, t->minutes, t->seconds);
}
 
void delay(void) {
long int t;
for (t = 1; t < DELAY; ++t);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.