DIGIT-ARC read-only archive · snapshot: July 23, 2026

How to use clrscr() function in gcc?

12 posts · originally from https://geek.digit.in/community/threads/how-to-use-clrscr-function-in-gcc.96469/

T
ThinkFree Original post #1
Aug 26, 2008 at 9:19 PM
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
Aug 26, 2008 at 9:32 PM
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
Garbage #3
Aug 26, 2008 at 10:18 PM
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
T
Aug 26, 2008 at 10:28 PM
^
I get the following error using system("clear"); inside main()
error: ‘system’ was not declared in this scope
T
Aug 26, 2008 at 10:51 PM
^Working now, but it's not clearing the screen.
QwertyManiac
Aug 26, 2008 at 10:51 PM
"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++...
T
Aug 26, 2008 at 10:53 PM
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
Garbage #9
Aug 26, 2008 at 11:20 PM
If using windows then try system("cls"); n if *nix then system("clear");

Actually, system() passes argument directly to shell...
QwertyManiac
Aug 26, 2008 at 11:21 PM
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! :)
Krazy_About_Technology
Aug 26, 2008 at 11:37 PM
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.
T
ThinkFree #12
Aug 27, 2008 at 10:06 PM
OK, will try ncurses