Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear the screen in ansi c. 1

Status
Not open for further replies.

mattias1975

Programmer
Jul 26, 2004
36
SE
Hello!

Does anyone know how to clear the screen in textmode in ansi C?
I am not allowed to use clrscr() in the conio.h file, because it is not a part of ansi C.

Thank you
 
> Does anyone know how to clear the screen in textmode in ansi C?
You can't, because ANSI-C makes no such assumption as to the existence of a screen.

It knows about stdin, stdout and stderr
But what lies behind them is outside the scope of the ANSI-C standard.

Simple example
[tt]myprog < file1 > file2[/tt]
has neither a keyboard or a screen

--
 
> I believe that if you use system("CLS") it will clear the screen.
But it isn't ANSI-C
The thing in quotes is highly system specific.


--
 
>> I believe that if you use system("CLS") it will clear the screen.
> But it isn't ANSI-C
> The thing in quotes is highly system specific.

An argument in
printf("Hello world\n");
is not a part of ANSI-C as well. It is not ANSI-C business what program does - clears the screen or not - it is thing of program specification. Program corresponds to ANSI-C rules, when it could be compiled with ANSI-C compiler - thats all.
clrscr() will also correspond to ANSI-C, when you will write it by yourself and include it to your project.
 
The ANSI C Standard includes library and i/o stream model specifications. There are no clrscr() and a screen as a notion in ANSI C - so, in that sense we can say that Borland's clrscr() is not ANSI C function (with its semantics and pragmatics)...
 
Well, if ANSI-C is thought not only as standard of language syntax but as standard of compatibility as well - then I aggree - no screens and no clrscr().
 
> An argument in
> printf("Hello world\n");
> is not a part of ANSI-C as well.
Yes it is - printf sends characters to the stdout stream.
Again, no mention of a screen here, just a stream.

As regards system, taken from the C99 draft
7.20.4.5 The system function
Synopsis
1 #include <stdlib.h>
int system(const char *string);
Description
2 If string is a null pointer, the system function determines whether the host
environment has a command processor. If string is not a null pointer, the system
function passes the string pointed to by string to that command processor to be
executed in a manner which the implementation shall document; this might then cause the
program calling system to behave in a non-conforming manner or to terminate.
Returns
3 If the argument is a null pointer, the system function returns nonzero only if a
command processor is available. If the argument is not a null pointer, and the system
function does return, it returns an implementation-defined value.
NULL is the only standard argument to system(), and that is to find out if there is a command interpreter which can cope with non-NULL arguments to system().
Everything else falls under the phrase "executed in a manner which the implementation shall document".

> clrscr() will also correspond to ANSI-C, when you will write it by yourself and include it to your project.
Maybe so, but you can be pretty sure that whatever you put inside that function will be implementation specific.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top