Questo è un semplice orologio per una applicazione "console":
codice:
#define STRICT
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
int main (void)
{
time_t t;
struct tm *tm;
int sec = -1;
BOOL bExit = FALSE;
HANDLE hStdOut;
CONSOLE_CURSOR_INFO cci;
hStdOut = GetStdHandle (STD_OUTPUT_HANDLE);
GetConsoleCursorInfo (hStdOut, &cci);
cci.bVisible = FALSE;
SetConsoleCursorInfo (hStdOut, &cci);
while (!bExit)
{
t = time (NULL);
tm = localtime (&t);
if (tm->tm_sec != sec)
{
printf ("\r%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
sec = tm->tm_sec;
}
Sleep (100); // 100 millisecondi
if (_kbhit ())
{
getch ();
bExit = TRUE;
}
}
printf ("\n");
cci.bVisible = TRUE;
SetConsoleCursorInfo (hStdOut, &cci);
return 0;
}
Ho usato alcune funzioni "standard" e alcune funzioni specifiche Win32. Avrei potuto usare solamente funzioni Win32 ma diventava un pochino più lungo.