PDA

View Full Version : How to clear screen with ncurses?



googleye
October 18th, 2011, 05:53 PM
Downloaded ncurses to be able to use clrscr() in my console applications but I have never installed a 3rd party header before and I have no idea how to do it. Help?

karlson
October 18th, 2011, 06:04 PM
Downloaded ncurses to be able to use clrscr() in my console applications but I have never installed a 3rd party header before and I have no idea how to do it. Help?

Why not install it from the repository? More importantly what does

locate ncurses.h


show?

googleye
October 18th, 2011, 06:12 PM
Couldn't find a package name so don't know how to install through terminal :p

Searching for ncurses.h and curses.h because curses.h is the header name:


***@ubuntu:~$ locate ncurses.h
/usr/include/ncurses.h
***@ubuntu:~$ locate curses.h
/home/***/.local/share/Trash/files/ncurses-5.9/include/curses.h
/home/***/.local/share/Trash/files/ncurses-5.9/include/curses.h.in
/home/***/.local/share/Trash/files/ncurses-5.9/include/curses.head
/usr/include/curses.h
/usr/include/ncurses.h

karlson
October 18th, 2011, 06:35 PM
Couldn't find a package name so don't know how to install through terminal :p

Searching for ncurses.h and curses.h because curses.h is the header name:


***@ubuntu:~$ locate ncurses.h
/usr/include/ncurses.h
***@ubuntu:~$ locate curses.h
/home/***/.local/share/Trash/files/ncurses-5.9/include/curses.h
/home/***/.local/share/Trash/files/ncurses-5.9/include/curses.h.in
/home/***/.local/share/Trash/files/ncurses-5.9/include/curses.head
/usr/include/curses.h
/usr/include/ncurses.h

Looks like ncurses is already installed.

googleye
October 18th, 2011, 07:14 PM
Well, still says clrscr() was not declared in this scope, and yes I've included the header file :D

Is clrscr() wrong? Or do I need to link the header to the install directory? I don't know how to do that :/

karlson
October 18th, 2011, 07:27 PM
Well, still says clrscr() was not declared in this scope, and yes I've included the header file :D

Is clrscr() wrong? Or do I need to link the header to the install directory? I don't know how to do that :/

It's actually clear().

googleye
October 18th, 2011, 07:32 PM
Now i got undefine reference to clear().

However code::blocks detected clear(it showed up in a list when i started typing it).

karlson
October 18th, 2011, 07:48 PM
Now i got undefine reference to clear().

However code::blocks detected clear(it showed up in a list when i started typing it).

Are you linking -lncurses to your project?

googleye
October 18th, 2011, 10:21 PM
Well no thats the thing, if I were compiling in the terminal I would know how. But in code blocks I'm lost.

Meghnaad
October 19th, 2011, 01:56 PM
If doing it with ncurses is not a compulsion,
you can use system() function from stdlib.h

Something Like this:

system("clear");

googleye
October 19th, 2011, 02:10 PM
Well I've read about it quite a few times and supposedly it's a major security risk to let system control your console or something like that. Even though my apps will never have any practical use and are only built to learn I want to get it in my system to never use that to clear the screen.

I have tried the simplest method i know of, Lots of endl's in a loop, but the downside is that afterwards the text prints out at the bottom of the screen. Looks really ugly :/

MeduZa
October 19th, 2011, 02:31 PM
Something Like this:

system("clear");

never do something like this, is a bad programing way!

also system("pause"); is really bad, only use that just for testing, but a cin or scan is better to pause the program.

I'm start using ncurses 1 mount ago but I really easy (like old way programing xD )

there a lot of help out there about ncurses, and the library is really easy to use:


//creating main window
initscr();
//clear screen, send cursor to position (0,0)
clear();

MeduZa
October 19th, 2011, 02:34 PM
dupe (delete me)

googleye
October 19th, 2011, 03:52 PM
Well my issue is that I don't know how to link -lncurses when compiling with code blocks, thanks for clarifying though :)

denago
October 20th, 2011, 03:10 PM
Well my issue is that I don't know how to link -lncurses when compiling with code blocks, thanks for clarifying though :)

http://stackoverflow.com/questions/5862757/how-do-i-link-to-a-library-with-codeblocks