Clearing screen before displaying menu 
Author Message
 Clearing screen before displaying menu

How can i clear the screen when my code is going to run on DOS and Unix:
I want to clear the screen prior to showing a menu.?
system("cls"); works fine under dos but not Unix.
Is there a way of clearing the screen on both OS or a way of detecting the
OS and then using system("clear"); for Unix if that is the OS that the code
is being run on.

Thanks Steve
--



Thu, 13 Oct 2005 06:29:57 GMT  
 Clearing screen before displaying menu
in comp.lang.c.moderated i read:

Quote:
>How can i clear the screen when my code is going to run on DOS and Unix:

there is no common method.

Quote:
>Is there [...] a way of detecting the OS and then using system("clear");
>for Unix if that is the OS that the code is being run on.

you have to compile the code for each platform anyway so it's trivial to
write a function to clear the screen which contains conditionally compiled
code, the condition being which platform for which it is being compiled.

--
bringing you boring signatures for 17 years
--



Fri, 14 Oct 2005 04:40:55 GMT  
 Clearing screen before displaying menu

Quote:

> How can i clear the screen when my code is going to run on DOS and Unix:
> I want to clear the screen prior to showing a menu.?
> system("cls"); works fine under dos but not Unix.
> Is there a way of clearing the screen on both OS or a way of detecting the
> OS and then using system("clear"); for Unix if that is the OS that the code
> is being run on.

There are ports of curses to DOS.
--



Fri, 14 Oct 2005 04:40:58 GMT  
 Clearing screen before displaying menu

Quote:

> Is there a way of clearing the screen on both OS

Not a single method that always works on both, no.

 > or a way of detecting the

Quote:
> OS and then using system("clear"); for Unix if that

 > is the OS that the code is being run on.

#if defined(unix) || defined(__unix__)

But it is strange that the only control you want over
the display format is to clear it.
--



Fri, 14 Oct 2005 04:41:02 GMT  
 Clearing screen before displaying menu

Quote:

> How can i clear the screen when my code is going to run on DOS
> and Unix: I want to clear the screen prior to showing a menu.?
> system("cls"); works fine under dos but not Unix.
> Is there a way of clearing the screen on both OS or a way of
> detecting the OS and then using system("clear"); for Unix if
> that is the OS that the code is being run on.

No. You should have seen this in your close perusal of the FAQ.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!
--



Fri, 14 Oct 2005 04:41:03 GMT  
 Clearing screen before displaying menu

wrote in comp.lang.c.moderated:

Quote:
> How can i clear the screen when my code is going to run on DOS and Unix:
> I want to clear the screen prior to showing a menu.?
> system("cls"); works fine under dos but not Unix.
> Is there a way of clearing the screen on both OS or a way of detecting the
> OS and then using system("clear"); for Unix if that is the OS that the code
> is being run on.

> Thanks Steve

Note that the C language does not define, know anything about, or
support a screen, and that all use of the system() function is
completely implementation-defined.

But the underlying answer to this is the same as it is to any question
concerning compiler or platform specific differences.  If you must
include such code in your programs (and often you must), then you need
to isolate the compiler/platform specific code from the standard code.

You can have two different files, one named dos_clear_screen.c and
another called unix_clear_screen.c, both of which expose a function
with the same name and signature, such as clear_the_dang_screen().

Since you have to build two physically different executables for the
two different operating systems, you use the appropriate source file
for the appropriate build.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
--



Fri, 14 Oct 2005 04:41:06 GMT  
 Clearing screen before displaying menu


Quote:
>How can i clear the screen when my code is going to run on DOS and Unix:
>I want to clear the screen prior to showing a menu.?
>system("cls"); works fine under dos but not Unix.
>Is there a way of clearing the screen on both OS or a way of detecting the
>OS and then using system("clear"); for Unix if that is the OS that the code
>is being run on.

Yes, send a suitably large number of '\n' to stdout.

--
ACCU Spring Conference 2003 April 2-5
The Conference you should not have missed
ACCU Spring Conference 2004 Late April
Francis Glassborow      ACCU
--



Fri, 14 Oct 2005 04:41:12 GMT  
 Clearing screen before displaying menu
On 26 Apr 2003 22:29:57 GMT in comp.lang.c.moderated, "Steve

Quote:

>How can i clear the screen when my code is going to run on DOS and Unix:
>I want to clear the screen prior to showing a menu.?
>system("cls"); works fine under dos but not Unix.
>Is there a way of clearing the screen on both OS or a way of detecting the
>OS and then using system("clear"); for Unix if that is the OS that the code
>is being run on.

Your compiler documentation may document predefined preprocessor
symbols defining which platform it is running on, and these may
be used to define the command to use, e.g.

        #ifdef  unix
        #define CLEAR_SCREEN    "clear"
        #else
        #define CLEAR_SCREEN    "cls"
        #endif

Maybe blasting a hundred newlines onto the screen from a string
would be simpler and quicker than firing up a shell/command
processor every time; or maybe just a few blank lines would be
enough: blowing away previous info on screens can be annoying to
users, a mistake often made by newbies.
If you're using screens seriously, you should be using the curses
library for portability.

Thanks. Take care, Brian Inglis         Calgary, Alberta, Canada
--

    fake address                use address above to reply
--



Fri, 14 Oct 2005 04:41:14 GMT  
 Clearing screen before displaying menu

Quote:

> How can i clear the screen when my code is going to run on DOS and Unix:
> I want to clear the screen prior to showing a menu.?

There is no such thing. The C language doesn't even assume ther *is*
anything like a "screen" in the system the program may be running on,
so clearly it can't define any standardized, portable means of
clearing it.

If you want to continute in this general direction, you should
consider using a portable screen management library, like "curses", to
do this work for you.
--

Even if all the snow were burnt, ashes would remain.
--



Fri, 14 Oct 2005 04:41:30 GMT  
 Clearing screen before displaying menu

Quote:


>>How can i clear the screen when my code is going to run on DOS and Unix:
>>I want to clear the screen prior to showing a menu.?
>>system("cls"); works fine under dos but not Unix.
>>Is there a way of clearing the screen on both OS or a way of detecting the
>>OS and then using system("clear"); for Unix if that is the OS that the code
>>is being run on.

>Yes, send a suitably large number of '\n' to stdout.

What is a suitably large number of '\n' for a Tektronix 401x terminal?

Dan
--
Dan Pop
DESY Zeuthen, RZ group

--



Sat, 15 Oct 2005 23:45:22 GMT  
 Clearing screen before displaying menu

Quote:



> >> How can i clear the screen when my code is going to run on DOS
> >> and Unix: I want to clear the screen prior to showing a menu.?
> >> system("cls"); works fine under dos but not Unix.
> >> Is there a way of clearing the screen on both OS or a way of
> >> detecting the OS and then using system("clear"); for Unix if
> >> that is the OS that the codeis being run on.

> >Yes, send a suitably large number of '\n' to stdout.

> What is a suitably large number of '\n' for a Tektronix 401x
> terminal?

ROTFLMAO.  or an ASR33 or TI 700.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!
--



Sun, 16 Oct 2005 07:20:43 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Init Screen w/o Clear Screen

2. Toolbar drop-down menu problem trying to display popup menu (IE Deskbar)

3. clearing screen

4. Clear Screen

5. ANSI clear screen

6. Help clearing screen

7. clearing the screen

8. clear screen for Linux

9. Clear screen and cursor-position

10. Clear screen

11. Clear screen

12. clearing the screen?

 

 
Powered by phpBB® Forum Software