Advertisement

How to clear a screen in C?

Started by September 20, 2002 04:12 AM
7 comments, last by Cinnamon 22 years, 1 month ago
I would like to know how to clear a screen in C. (maybe in C++ too for my future stydies)
Try - system("cls");
Advertisement
Neither C nor C++ know anything about screens and whatnots, they only see streams and files.

For console manipulation in dos-windows, see conio.h
For console manipulation in *NIX, see curses.h

Note: system("cls") is slow ... and assumes you have an operating system with a 'cls' command (neither is a given )

Edit: See also MSDN q99261

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]


[edited by - Fruny on September 20, 2002 5:48:44 AM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Depends on the compiler.
Use clrscr() defined in conio.h

That''s for Borland Turbo C++. However, this is not available in Microsoft Visual C++, it has another function. Dunno in DJGPP or gcc.

My compiler generates one error message: "does not compile."
My compiler generates one error message: "does not compile."
I am having the same question, how do I clear the screen in Microsoft Visual Basics 6.0 using the iostream commands instead of using cornio.h
#include <iostream>

Sorry that was a typo, I meant to type Visual C++ 6.0 sorry for the mix up.

[edited by - Surg AKA Kunark on September 20, 2002 2:35:05 PM]
~~Johnathan~~LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF
quote: how do I clear the screen in Microsoft Visual Basics


Surg, are you joking around? The funny thing is we have people here at work who go around talking about Visual "Basics" and C+ (not to be confused with C or C++). It is a big pet peeve of mine. That should be grounds for immediate termination.
bugawk?
Advertisement

  for (i = 0; i < SCREEN_HEIGHT; printf("\n", i++));  


My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

BeerNuts,
Why did you pass i++ to printf()?
I would have written

  for (i = 0; i < SCREEN_HEIGHT; printf("\n"), ++i));or evenfor (i = 0; i < SCREEN_HEIGHT; ++i)    printf("\n");  

Is there some benefit to passing i++ to printf()?
Just wondering.
When using the Windows calculator program, always remember to clear any values from memory before exiting to prevent burn-in.
quote: Original post by chris01
Try - system("cls");



Sorry, only fools call system() for trivial tasks. In UNIX, a bad programmer is one who calls system ("rm file") instead of using unlink(). system() is saying ''I don''t know so just fake it''.

This topic is closed to new replies.

Advertisement