CLEAR SCREEN? 
Author Message
 CLEAR SCREEN?

how do you clear the screen in a c program?

in dos, the equivalent is the command "cls"...i've tried the \r command,
with many \r's strung together, but that only goes back to the beginning of
the line.  PLEASE HELP!

thanks, in advance!
matt



Sun, 10 Dec 2000 03:00:00 GMT  
 CLEAR SCREEN?


Quote:

> how do you clear the screen in a c program?

> in dos, the equivalent is the command "cls"...i've tried the \r command,
> with many \r's strung together, but that only goes back to the beginning of
> the line.  PLEASE HELP!

> thanks, in advance!
> matt


<Jack>

Somehow when you read the FAQ for comp.lang.c like you were supposed
to do before posting here, you missed this one.  See the links below.

Outputting '\n' characters (not commands) instead of '\r' is one way.

c.l.c. FAQ, text & hypertext:
Text ftp://rtfm.mit.edu/pub/faqs/C-faq/faq
Text ftp://rtfm.mit.edu/pub/usenet-by-group/comp.lang.c/C-FAQ-list
Hypertext http://www.eskimo.com/~scs/C-faq/top.html

</Jack>



Sun, 10 Dec 2000 03:00:00 GMT  
 CLEAR SCREEN?

Quote:

> how do you clear the screen in a c program?

> in dos, the equivalent is the command "cls"...i've tried the \r command,
> with many \r's strung together, but that only goes back to the beginning of
> the line.  PLEASE HELP!

No.  Help yourself, read the FAQ.  \r is not a command, DOS is off
topic, clearing the screen cannot be done.  Read the FAQ.

See http://www.eskimo.com/~scs/C-faq/top.html

--

I believe we can change anything.
I believe in my dream.
    - Joe Satriani



Sun, 10 Dec 2000 03:00:00 GMT  
 CLEAR SCREEN?

Quote:

> how do you clear the screen in a c program?

Hi MB,

This question is so frequently asked in this newsgroup (for
instance about three times last week) that it has been included
in the comp.lang.c FAQ list. Please look for:
  19.4:   How can I clear the screen?
          How can I print things in inverse video?
          How can I move the cursor to a specific x, y position?

The short answer is that you can't do it in standard C. You'll
have to use specific features of your compiler or OS.

You can get the FAQ at http://www.eskimo.com/~scs/C-faq/top.html or
at ftp://rtfm.mit.edu/pub/usenet/comp.lang.c/C-FAQ-list and it gets
posted to this newsgroup and to news.answers regularly (at the
beginning of each month).

Stephan
(initiator of the campaign against grumpiness in c.l.c)



Sun, 10 Dec 2000 03:00:00 GMT  
 CLEAR SCREEN?

|> how do you clear the screen in a c program?

Very carefully. Not very portably.

|> in dos, the equivalent is the command "cls"...i've tried the \r command,
|> with many \r's strung together, but that only goes back to the beginning of
|> the line.  PLEASE HELP!

/* Copyright 1903-1999 Regents of the School of Hard Knocks.
 * All persons living or dead are accidental.
 * Use at your own risk.
 *
 * Not responsible for typos or lost property.
 * This code is written to be as portable as possible, but probably
 * won't work on YOUR system.
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc , char **argv){

void punt(void);

if(argc < 2){
#ifdef __BORLANDC__
  clrscr();
#else
  punt();
#endif
  printf("usage: %s text|netscape\n", argv[0]);
  puts("Oh, yeah, you wanted your screen cleared. Sorry.");
  exit(0);

Quote:
}

  /* The following is slightly Unix-specific,
   * probably in more ways than I mean.
   */
  if(!strcmp(argv[1], "text"))
    return system("lynx -dump http://www.eskimo.com/~scs/C-faq/q19.4.html");
  else if(!strcmp(argv[1],"netscape"))
    return system("netscape http://www.eskimo.com/~scs/C-faq/q19.4.html");
  else punt();

return 0;

Quote:
}

void punt(void){
    int i;

    system("clear"); /* hope this doesn't do something unexpected...  */
    system("cls"); /*  Clean and Load Solvent? */

    for(i = 0; i< 50; i++) puts("\n");
    puts("\f");

Quote:
}



Sun, 10 Dec 2000 03:00:00 GMT  
 CLEAR SCREEN?


Quote:
> how do you clear the screen in a c program?

You don't. Now stop asking this question. Read the FAQ and lurk before posting.

--
(initiator of the campaign for grumpiness where grumpiness is due in c.l.c)

Where, oh where, has the netiquette gone? Where, oh where, could it be?



Sun, 10 Dec 2000 03:00:00 GMT  
 CLEAR SCREEN?

Quote:

>Power Down.



>> how do you clear the screen in a c program?

And it's portable !!!

--
Sylvain Poirier

___



Tue, 12 Dec 2000 03:00:00 GMT  
 CLEAR SCREEN?

Quote:


> > how do you clear the screen in a c program?

> You don't. Now stop asking this question. Read the FAQ and lurk before posting.

Hey bag_of_wind,

Is it too much to answer a very simple and straightforward question. If you don't
know how
then just say so, or better yet, say nothing. There is no need to flame the poor
guy for asking
a perfectly innocent question.

In answer to the original question:

For Borland C and C++ compilers, and also for Microsoft's series of compilers, do
the
following:

#include <bios.h>        /* Clearing the screen uses bios calls on a PC */

then in your code, include the function call:

    clrscr();

That's all there is to it. (It may be too complicated for bag_of_wind though)

Regards from down-under.

Gerry Cohn



Sat, 16 Dec 2000 03:00:00 GMT  
 CLEAR SCREEN?

Quote:



> > > how do you clear the screen in a c program?

> > You don't. Now stop asking this question. Read the FAQ and lurk before posting.

(Snip troll)
> In answer to the original question:

> For Borland C and C++ compilers, and also for Microsoft's series of >compilers, do the following:

> #include <bios.h>        /* Clearing the screen uses bios calls on a PC */

> then in your code, include the function call:

>     clrscr();

Your boss walks into your cubicle.  He says, great program you just
wrote!  I especially like how it clears the screen. However else you
change the program, that feature simply must stay.  Now I'd like you
to compile it for a few other systems.  A Linux box.  An Amiga.  A
Mac.  And, our best microwave, The FOO-42X.  Surely this won't be a
problem for you, since you always write such easily portable code!

--

"Strategy and appropriate use of the *available* resources does NOT
equate to godhood. --Barry Kearns"



Sat, 16 Dec 2000 03:00:00 GMT  
 CLEAR SCREEN?

Quote:

> Hey bag_of_wind,

[...]

Quote:
> In answer to the original question:

Hey,

 I understand your idea, however I suggest you to follow this newsgroup
for more than, say a month, and overthink your posting again. The number
of off-topic postings here has grown to such an incredible number that it
is a matter of survival to point out what is on-topic here and what is not.

I think it's normal for anybody new to a group to browse the last weeks
or months searching for subject lines similar to what he / she wants to
know before posting for the first time. If your News server does not keep
the messages long enough, try www.dejanews.com, which is an excellent
source for browsing old threads.

Even better, the FAQ lists normally cover over 80% of what's commonly
asked here. There were even 3 different ClearScreen threads in the last
four weeks here, so people even started thinking of renaming comp.lang.c
to comp.lang.clearscreen.

Regards,

Herbert

--

* Free Speech Online!!! Support the Blue Ribbon Campaign! *



Sat, 16 Dec 2000 03:00:00 GMT  
 CLEAR SCREEN?

Quote:

> Hey bag_of_wind,

Hi clueless_wonder,

Quote:
> Is it too much to answer a very simple and straightforward question.

Sometimes it takes a bit of knowledge to recognize a complicated
(and BTW off-topic) question.

Quote:
> If you don't know how then just say so, or better yet,
> say nothing. There is no need to flame the poor guy for asking
> a perfectly innocent question.

We all know *several* ways to answer the question, and this is the
main hint at the complexity involved in answering it. It is *not*
a simply and innocent question, be cause there is not simple
single answer to it. Almost every compiler tends to require a different
answers, and with some it is *not* possible at all to clear the
screen.

Quote:
> For Borland C and C++ compilers, and also for Microsoft's series of > compilers, do the following:

> #include <bios.h>        /* Clearing the screen uses bios calls on a PC */

Not necessarily. And you've also picked the wrong header file.

Quote:
> then in your code, include the function call:

>     clrscr();

This is a Borland specific function, that is not supplied by Microsoft
at all. Indeed you can not expect to find it on any other compiler.

Stephan
(initiator of the campaign against grumpiness in c.l.c)



Sat, 16 Dec 2000 03:00:00 GMT  
 CLEAR SCREEN?




|> > > how do you clear the screen in a c program?

|> > You don't. Now stop asking this question. Read the FAQ and lurk before posting.

|> Hey bag_of_wind,

|> Is it too much to answer a very simple and straightforward question.

No. Where was the simple and straightforward question?

The question was one which:

a. Has no general answer
b. Is answered as well as possible in the comp.lang.c FAQ, which
   anyone with ony manners at all would read before posting a question
   here
c. Is (despite (b) above) asked in this newsgroup about three times a
   week lately.

Netiquette  requires reading a newsgroup for a while, and reading its
FAQ, before posting. Common sense would also suggest reading the group
a while before posting, eh?

|> If you don't know how then just say so, or better yet, say nothing.

I would be willing to bet a large sum of money that firewind knows how
to clear the screen on a half-dozen systems.

|> There is no need to flame the poor guy for asking
|> a perfectly innocent question.

ITYM "for asking a much-asked question, thereby demonstrating that he
didn't bother to read the FAQ or the newsgroup itself before asking."

|> In answer to the original question:

|> For Borland C and C++ compilers, and also for Microsoft's series of
|> compilers, do the following:

The poster didn't ask how to clear the screen on a PC; he asked how to
clear the screen in a C program.

|> #include <bios.h>        /* Clearing the screen uses bios calls on a PC */

This is also wrong. You can USE BIOS calls to clear the screen,
but here, you're using clrscr(), which (IIRC) his declared in conio.h.

|> then in your code, include the function call:

|>     clrscr();

|> That's all there is to it. (It may be too complicated for bag_of_wind though)

Maybe bag_of_wind is aware that all the world isn't a DOS box?

I'd say his (somewhat rude) pointer to the correct answer was better
than your non-portable and incorrect answer.

--
* "And there _is_ a real world. In fact, some of you
*    are in it right now."  -- Gene Spafford



Sat, 16 Dec 2000 03:00:00 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Init Screen w/o Clear Screen

2. Clearing screen before displaying menu

3. clearing screen

4. Clear Screen

5. ANSI clear screen

6. Help clearing screen

7. clear screen for Linux

8. Clear screen and cursor-position

9. Clear screen

10. Clear screen

11. clear screen for Linux

12. Clear Screen

 

 
Powered by phpBB® Forum Software