473,240 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,240 software developers and data experts.

different "system()" for different OS

I want

system ("CLS")

if the system is WINDOWS

system ("CLEAR")

is the OS is a UNIX like.

How I have to do?

Nov 14 '05 #1
9 1927

"/* frank */" <__*******@despammed.com> wrote in message
news:2k************@uni-berlin.de...
I want

system ("CLS")

if the system is WINDOWS

system ("CLEAR")

is the OS is a UNIX like.

How I have to do?


use the pre-processor e.g.

#ifdef _WINDOWS
system("cls");
#else
system("clear");
endif

I am not sure what to check for, if you want to do more checks than this,
but you get the idea
Allan
Nov 14 '05 #2
/* frank */ <__*******@despammed.com> wrote:
I want system ("CLS") if the system is WINDOWS system ("CLEAR") is the OS is a UNIX like.


First of all, Unix is case-sensitive.

Second of all, the preprocessor is your friend.

void my_clear_screen(void)
{
#ifdef SYS_IS_WINDOWS
system("cls");
#elif SYS_IS_UNIX
system("clear");
#else
#error my_clear_screen not supported on this platform
#endif
}

Of course, it is up to you to define SYS_IS_WINDOWS or SYS_IS_UNIX.

--
Alex Monjushko (mo*******@hotmail.com)
Nov 14 '05 #3

"/* frank */" <__*******@despammed.com> a écrit dans le message de
news:2k************@uni-berlin.de...
I want

system ("CLS")

if the system is WINDOWS

system ("CLEAR")

is the OS is a UNIX like.

How I have to do?


Most of the windows compilers I know support the

_WIN32

symbol that is automatically defined.

#ifdef _WIN32
.... windows specific code
#else
... other systems
#endif

If you do not like #ifdef'ed code,
in both systems this would clear the screen:

void cls(void)
{
for (int i = 0; i<500;i++)
printf("\n");
}

Inefficient, granted, but it would work :-)

jacob
Nov 14 '05 #4
"jacob navia" <ja***@jacob.remcomp.fr> writes:
[...]
If you do not like #ifdef'ed code,
in both systems this would clear the screen:

void cls(void)
{
for (int i = 0; i<500;i++)
printf("\n");
}

Inefficient, granted, but it would work :-)

jacob


It would also (on many systems) leave the cursor at the bottom of the
screen whereas "CLS" or "clear" typically leaves the cursor at the top
of the screen.

It also assumes that stdout points to a "screen" of some sort (which,
depending on the environment in which the program is run, may be a
perfectly reasonable assumption).

<OT>You should also consider why you want to clear the screen in the
first place. If a program other than a full-screen editor
unnecessarily erases information from *my* screen, I consider it a
hostile act.</OT>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5

"Keith Thompson" <ks***@mib.org> a écrit dans le message de
news:ln************@nuthaus.mib.org...
"jacob navia" <ja***@jacob.remcomp.fr> writes:
[...]
If you do not like #ifdef'ed code,
in both systems this would clear the screen:

void cls(void)
{
for (int i = 0; i<500;i++)
printf("\n");
}

Inefficient, granted, but it would work :-)

jacob


It would also (on many systems) leave the cursor at the bottom of the
screen whereas "CLS" or "clear" typically leaves the cursor at the top
of the screen.

It also assumes that stdout points to a "screen" of some sort (which,
depending on the environment in which the program is run, may be a
perfectly reasonable assumption).

<OT>You should also consider why you want to clear the screen in the
first place. If a program other than a full-screen editor
unnecessarily erases information from *my* screen, I consider it a
hostile act.</OT>


I do not want to clear any screen. You are answering to the original poster
isn't it?
Nov 14 '05 #6
In <cb**********@news-reader5.wanadoo.fr> "jacob navia" <ja***@jacob.remcomp.fr> writes:

If you do not like #ifdef'ed code,
in both systems this would clear the screen:

void cls(void)
{
for (int i = 0; i<500;i++) ^^^^^^^^^
Syntax error in C89.
printf("\n");
}

Inefficient, granted, but it would work :-)


Would it? Try it on an xterm (Unix's most popular terminal emulator for
X11) in Tektronix mode...

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #7
In <ln************@nuthaus.mib.org> Keith Thompson <ks***@mib.org> writes:
<OT>You should also consider why you want to clear the screen in the
first place. If a program other than a full-screen editor
unnecessarily erases information from *my* screen, I consider it a
hostile act.</OT>


It's not editors vs others programs, it's programs operating in full
screen mode vs programs operating in teletype mode.

ANY program operating in full screen mode (top and friends, advanced
pagers, visual editors, text mode web browsers, games, interfaces to
various services etc etc) is supposed to start by clearing the screen).

NO program operating in tty mode has any business to attempt clearing
the "screen". If it's operating in tty mode, it should assume that both
paper and glass teletypes can be used as output devices.

And if someone wants to write a full screen application, clearing the
screen is the last of his worries, as the API used for generating full
screen output will provide a primitive for this purpose.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #8
In <2k************@uni-berlin.de> /* frank */ <__*******@despammed.com> writes:
I want

system ("CLS")

if the system is WINDOWS

system ("CLEAR")

is the OS is a UNIX like.

How I have to do?


Identify reserved identifiers predefined by the preprocessors running on
the platforms of interest and test their existence. Untested example:

#ifdef _WIN32
#define COMMAND "CLS"
#elif defined __unix__
#define COMMAND "clear"
#else
#error "Platform not supported."
#endif

and, of course, use COMMAND as the argument of the system() call.

I hope this is only a generic example: no well designed program has
any business invoking the shell command that clears the screen.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #9
"jacob navia" <ja***@jacob.remcomp.fr> writes:
[...]
I do not want to clear any screen. You are answering to the original poster
isn't it?


Of course. Actually, this being Usenet, I'm talking to anyone who
happens to read my article. (I could have made that clearer.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mel | last post by:
try the following code in IE and Mozila and you get 2 different padding <fieldset> <legend>This is a test</legend> <div style=padding:10px>hello</div> </fieldset> HOW CAN I AVOID THIS ? ...
1
by: s2224 | last post by:
Hi, is it permissible according to iso c++ standard, that there is different entry points for different type of applications such as WinMain for windows application and DllMain for dll type? ...
3
by: Klemens | last post by:
The same dynamic sql statement at the same database needs from one application seconds and from another milliseconds. Isolation level and optimization level are the same. What else could be...
9
by: Tony Epton | last post by:
I have done a partial conversion of a large MS Access batch processing program to use a SQL server 2000 back end. All I have done is move all the access tables in to SQL server and give them...
43
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
3
by: Ryan Liu | last post by:
Hi, I have a big urgent problem to solve. I used to use Windows 2000 Chinese version, now I installed Windows XP (English) system. The problem is not about 2000 or XP, it is about English...
3
by: pradeep | last post by:
Hello, Can any one tell me different functions or properties of javascript which are gives different outputs on different browsers ? Thanks in advance. Bye
3
by: haroldunlimited | last post by:
HI guyz, Im making a ms access database and I would like to use different background for the different user level,once they log in.how is this possible? thanks guyz.....
10
mariko
by: mariko | last post by:
I know that there are different margins in different browsers. I tried the Global Reset and it didn't help. I am a beginner, so I might be doing something wrong and I won't be offended if you...
1
by: saritha pulluri | last post by:
I get different outputs in different browsers. Please help me to find a solution. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.