Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************
- A very simple program to implement a stopwatch
- youtube.com/vamcode
- ***************/
- #include<stdio.h>
- #include<unistd.h>
- int main(){
- int hours = 0 , minutes = 59 , seconds = 56 , milliseconds = 0;
- while(1){
- printf("\r\t%.2d HOURS : %.2d MINUTES : %.2d SECONDS : %d",hours, minutes,seconds, milliseconds);
- fflush(stdout);
- usleep(1000);
- ++milliseconds;
- if(milliseconds == 1000){ /*edit: previously was if(milliseconds == 999) */
- milliseconds = 0;
- ++seconds;
- }
- if(seconds == 60){
- milliseconds = 0;
- seconds = 0;
- ++minutes;
- }
- if(minutes == 60){
- milliseconds = 0;
- seconds = 0;
- minutes = 0;
- ++hours;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement