Skip to content

Instantly share code, notes, and snippets.

@MinhasKamal
Created November 11, 2015 18:21
Show Gist options
  • Save MinhasKamal/8081f1ea477419f66ea1 to your computer and use it in GitHub Desktop.
Save MinhasKamal/8081f1ea477419f66ea1 to your computer and use it in GitHub Desktop.
/**
* Developer: Minhas Kamal (BSSE-0509, IIT, DU)
* Date: Aug-2013
**/
#include <stdio.h>
#include <time.h>
int main()
{
printf("*#This is a stopwatch#*\n\n\n");
printf("**Press 'p' to pause.\n");
printf("**Press any key to start & to stop.");
getch();
system("cls");
printf("\t\t*#This is a stopwatch#*\n\n\n");
clock_t s, n;
s = clock();
while(1){
while(1){
n=clock();
printf("\r");
printf("Time-\t %d : %d : %d ", ((n-s)/1000)/60, ((n-s)/1000)%60, (n-s)%1000);
if(kbhit()) break; //kbhit() does not read the character
}
if(getch()=='p'){
printf("\rTime-\t %d : %d : %d ", ((n-s)/1000)/60, ((n-s)/1000)%60, (n-s)%1000);
getch();
}
else break;
s=s+(clock()-n); //split time
//s=clock(); //lap time
}
printf("\rTime-\t %d : %d : %d ", ((n-s)/1000)/60, ((n-s)/1000)%60, (n-s)%1000);
getch(); getch(); //to read the extra characters
printf("\n\n\n");
return 0;
}
@heenahmed
Copy link

kbhit() is in <conio.h> but u haven't used it here ..how are you able to execute it? when i am including <conio.h> , i am getting fatal error that no such directory exist .. please help

@haller33
Copy link

haller33 commented Dec 5, 2023

@heenahmed this is a DOS library... probably on the Windows... at the time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment