Skip to content

@carlosbrando /gist:960645
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Mostra um relógio por software
/* 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.