je debute en c et je cherche comment arreter le timer en appuyant sur une touche de clavier.
j'ai utilise getch() mais le timer attend la saisie mais il doit continuer jusqu'a la saisie du caractere 'r'.
c'est le code:
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
int main ()
{
time_t start,end;
int sec=0;
int min=0;
int heur=0;
int reglage=0;
char r='a';
// char szInput [256];
int dif;
time (&start);
while((r!='r')){
//system("cls");
printf ("\n\n\t l'heure actuel\n\n ");
time(&end);
dif =(int)(difftime (end,start));
printf ("\n\n\t\t%d : %d : %d\n",((dif++ / 3600) % 24),((dif++ / 60) % 60),dif % 60 );
Sleep(1000);
r=getch();
}
return 0;
}