Connecting Tech Pros Worldwide Forums | Help | Site Map

Clearing the console screen in gcc

Newbie
 
Join Date: Sep 2006
Posts: 1
#1: Sep 6 '06
Hi,

How do I clear the console screen in gcc compiler.
It does not accept clrscr() or system(cls);
I dont want to print blank lines or use putchar(' \f');
Is there any defined function in gcc like clrscr() to clear the console?

Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,188
#2: Sep 6 '06

re: Clearing the console screen in gcc


My question would be why would you want to. Most people using the console would be what I would term advanced users. If they want the console cleared before running you program then they are capable of doing it themselves.

I have seen a fair number of posts on usenet breating programs that clear the console before running especially if they don't restore it when they finish (which is much harder to do).
Member
 
Join Date: Sep 2006
Posts: 61
#3: Sep 7 '06

re: Clearing the console screen in gcc


use system(clear)
Newbie
 
Join Date: Sep 2006
Posts: 23
#4: Sep 7 '06

re: Clearing the console screen in gcc


i happen to follow the advice and i have ran this program and got the following errors

#include<stdio.h>

main()
{
printf("hai");
system(clear);
}

d1.c: In function `main':
d1.c:6: `clear' undeclared (first use in this function)
d1.c:6: (Each undeclared identifier is reported only once
d1.c:6: for each function it appears in.)

how it can happen?
Member
 
Join Date: Sep 2006
Posts: 61
#5: Sep 7 '06

re: Clearing the console screen in gcc


First of all you didn't include the header file for the API "system". I think you don't know the prototype of API "system". The prototype of system is

int system(const char *string);

And in the program you written above, you passed just clear but not as a string. So try the following code

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

main()
{
printf("hai");
system("clear");
}


See the man page of every API before using. It will help in self learning.
Reply


Similar C / C++ bytes