How to use clrscr() function in gcc?

Status
Not open for further replies.

ThinkFree

Technomancer
Is it possible to use functions like clrscr(), gotoxy() in gcc? I have found that conio.h is for windows only, but is there any workaround to be able to use it in linux?
 

QwertyManiac

Commander in Chief
There are alternatives upto a possible-extent available in the ncurses libraries (Only available for POSIX systems). Link has a tutorial too, the basics are easy stuff :)

There are clear() and move() functions in ncurses that can help.
Code:
man curs_clear
man curs_move
# For more help.
 

Garbage

God of Mistakes...
or use system("clear"); or system("cls") which don't require any external lib. But thats not a good practice. But it servers the purpose ! :p
 
OP
T

ThinkFree

Technomancer
^
I get the following error using system("clear"); inside main()
error: ‘system’ was not declared in this scope
 

QwertyManiac

Commander in Chief
"clear" will not always work cause Linux's method of clearing the terminal is different than Windows and will sometimes give you good WTF moments :)

system() not being found is very weird indeed, I have clue on this, but try including <stdlib.h> or <cstdlib> if C++...
 
OP
T

ThinkFree

Technomancer
No error given be compiler with stdlib but still not clearing the screen.

system() not being found is very weird indeed, I have clue on this, but try including <stdlib.h> or <cstdlib> if C++...
Forgot to type "NO"?
 

Garbage

God of Mistakes...
If using windows then try system("cls"); n if *nix then system("clear");

Actually, system() passes argument directly to shell...
 

QwertyManiac

Commander in Chief
Ah yes I did forget to include a "no". But system("clear") will not help in the same way as clrscr() of conio.h. The only way is ncurses if you want all features of dos.h/conio.h/etc windows stuff, and its a lot more powerful than that. You might just love it, why not give the link's tutorial a try? I liked it! :)
 
I guess you want some kind of unified solution so that your program works fine whether compiling in Windows or Linux. For that you'll have to do the one time dirty task of creating the "unified versions" of these functions in one of your custom header file. use #ifdef construct to comment out sections of your code that are irrelevent while running on a particular OS. Best way to create these unified version is to use ncurses for linux/unix and conio.h for windows.
 
Status
Not open for further replies.
Top Bottom