Question:

C can you output a number and have it count up in place?

by Guest31675  |  earlier

0 LIKES UnLike

I would like to output a word (or two) such as HD size, word count, etc. and then an int. The I would like for that int to stay in the same place in the cmd but increase in value as i add to it to appear as if it was counting the words in a document or the number of bytes in a hd. Is it possible to do this? If so how? And if not is there another way to do what i'm describing? Please be as detailed as possible including necessary header files.

Thanks in advance

 Tags:

   Report

3 ANSWERS


  1. display

    erase

    then display.

    at a fast rate, it should show as a counter.


  2. It totally depends what you're displaying on. If, for example, it's a printer, this is obviously not going to be possible.

    If it's an ANSI-compatible terminal (which most text displays these days are), then you can use the appropriate sequence to 'back up' and overwrite your previous characters.

    Have a look at the cursor position information in the link below.

  3. If this is on stdout, replace the \n with a \r to move back to the start of the same line, then reprint the entire line with the new value(s).  

    This can look quite sophisticated for simple text output, especially if you figure out beforehand how big your values can get and leave the appropriate number of blanks so the fixed text doesn't move when the numbers change.

    Hope that helps.

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.