# How to use clrscr() function in gcc?



## ThinkFree (Aug 26, 2008)

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)

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. 
	
	



```
man curs_clear
man curs_move
# For more help.
```


----------



## Garbage (Aug 26, 2008)

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 !


----------



## ThinkFree (Aug 26, 2008)

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


----------



## Krazy_About_Technology (Aug 26, 2008)

include stdlib.h in your program.


----------



## ThinkFree (Aug 26, 2008)

^Working now, but it's not clearing the screen.


----------



## QwertyManiac (Aug 26, 2008)

"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++...


----------



## ThinkFree (Aug 26, 2008)

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 (Aug 26, 2008)

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

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


----------



## QwertyManiac (Aug 26, 2008)

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)

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.


----------



## ThinkFree (Aug 27, 2008)

OK, will try ncurses


----------

