Home c Stopwatch in C (Linux)

Stopwatch in C (Linux)




Develop a program that simulates the operation of the digital stopwatch, which allows you to measure time intervals to within a millisecond. The time interval to be measured from the time of start of the program until the interactive interrupt its operation by a signal from the keyboard. Changes in the measured time within the interval to be displayed in one line of the standard output stream (stdout). The output format must contain fields for displaying hours, minutes and seconds, separated by a colon and the field for displaying milliseconds which is separated from the second symbol field point. Update your information in the fields should occur at intervals of one millisecond specified format. At the same time should be modified only the output line numbers, whose values ​​have changed compared to the previous displayed point in time.

1) How to make a modification only change the numbers? And indeed the whole line (\ r is not an option, updates the entire row)
2) As in this case, make a stop at the touch of a button (ctrl + C is not desirable)

# include & lt; stdio.h & gt;
#Include & lt; Time.h & gt;
  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 & gt; 100)
      sec = sec + 1;
      ms = ms - 100;
      start = end;
    if (sec & gt; 59)
      min = min + 1;
      sec = 0;
    if (min & gt; 59)
      hrs = hrs + one;
      min = 0;
    printf ( "% d:% d:% d% d \ n.", hrs, min, sec, ms);

Answer 1, Authority 100%

There is an option – either to use the \ r , and output a new line over the old (thus look numbers will be changed … it does not), or (once you this option not suitable)

use the “backspace” to the desired number of characters and print only the changed numbers.

I have recorded everything in a row, that can be stored. After that, the two lines would be compared, and watched where the difference begins.

With the keys – if you already have the same & lt; conio.h & gt; , then check in the same cycle if the button is pressed, there was not, and if there was – then what …

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions