Advertisements

"Joseph" <> wrote in message
news:Xns9566AE53A1569wutongjoe@203.96.216.21...
> Hi all,
>
> I am doing my assignment and have a question ,how can I clear the standard
> output(screen)?
>
> following is the fake code:
>
> =====================================
>
> main(){
>
>
> for loop(int i++){
>
> printf (" %d",i);
>
> }
>
> }
> ====================================
>
> the problem is,I want to clean the previous output number and then print
> only the new number .So it is like a on-screen counter somehow.

This sounds pretty similar to a FAQ. See the FAQ
(http://www.parashift.com/c -faq-lite/), section 15 ("Input/output via
<iostream> and <cstdio>"), question 20 ("How can I clear the screen? Is
there something like clrscr()?").

There are some (non-portable) ways to do what you want. For instance, on
Windows, using VS.NET2003, the following code displays a counter that is
periodically overwritten:

Joseph <> writes:
> Hi all,
>
> I am doing my assignment and have a question ,how can I clear the standard
> output(screen)?
>
> following is the fake code:
>

[...]
> the problem is,I want to clean the previous output number and then print
> only the new number .So it is like a on-screen counter somehow.

One way is to print out a lot of blank lines, so the old output will
disapaire, another way is using the preprozessor:
//do this in a seperate header file
#if defined LINUX
#define CLEAR_SCREEN clear
#elif defined WIN32
#define CLEAR_SCREEN cls
//for more platforms
#endif

or just spliting it into a front and a back end, by using in the backend
the platform specfic functions or libraries.

On Linux for example ncurouses and on windows for example the code that
David posted.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!