Develop a program that simulates the operation of a digital stopwatch, which allows you to measure time intervals with millisecond accuracy. The time interval should be measured from the moment of launching the program to the moment of interactive interruption of its work on the signal from the keyboard. The change in time within the measured interval should be displayed in one line of the standard output stream (stdout). The output format should contain fields for displaying hours, minutes and seconds, separated by a colon, and a field for displaying milliseconds, which is separated from the seconds field by a period symbol. Updating information in the fields of the specified format should occur at intervals of one millisecond. In this case, only those digits of the output line whose values have changed relative to the previously displayed time point should be modified.
1) How to make a modification of only a changed digit? And in general, the line as a whole (\ r is not an option, updates the entire line)
2) As in this case, make a stop by pressing the key (Not ctrl + C is desirable)
#include <stdio.h> #include <time.h> int main() { int start, end; int ms= 0; int ns= 0; int sec=0 , min=0 , hrs=0; start = clock (); while (1) { end = clock (); ns= end - start; ms = ns / 10; if (ms>100) { sec = sec + 1; ms= ms - 100; start= end; } if (sec > 59) { min = min+1; sec= 0; } if (min > 59) { hrs = hrs + 1; min=0; } printf ("%d:%d:%d.%d\n",hrs, min, sec, ms ); } }