Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent :C Programming Under Linux

Status
Not open for further replies.

charu

IS-IT--Management
May 20, 2001
29
0
0
IN
Hi,
I have worked on Linux and DOS os & now started working on Linux.I have started programming in C lang under Linux and have certain difficulties:
1.How to use the functions in ncurses library.
e.g. to clear screen,how to use clear() function in ncurses library or is there any alternative for this clear function for linux platform.
All ideas will be welcomed


 
hello Ifincham,
I saw the link you have given to me.
But sorry to say I am not getting it.
So can you guide me more on this with some small example.
Thanks in advance.
 
Hi,



int clear(void);

clears the screen



int erase(void);

writes blanks to every position of window



int cleartobot(void);

clears the screen from the current cursor location to the bottom of the window.



int clrtoeol(void);

erases current line from the cursor to the right margin



All the above have window specific versions :



int werase(WINDOW *win);

int wclear(WINDOW *win);

int wclrtobot(WINDOW *win);

int wclrtoeol(WINDOW *win);



See 'man 3 clear'



Regards



 
hello Iffincham,
Using the help provided by u ,I wrote following simple code.

#include<stdio.h>
#include<curses.h>
main()
{ int clear(void);
printf(&quot;hello&quot;);
clear();
printf(&quot;here&quot;);
}


But it doesn't work.
It is not clearing the screen after printing hello.

help please.
 
Hi,



Try this as an example :



/* ntest.c */

#include <stdlib.h>

#include <curses.h>



int main(void)

{

if((initscr()) == NULL) {

perror(&quot;intscr&quot;);

exit(EXIT_FAILURE);

}

printw(&quot;a ncurses window\n&quot;);

refresh();

sleep(3);

clear();

printw(&quot;bye bye....\n&quot;);

refresh();

sleep(3);

endwin();



exit(0);

}





Put that into ntest.c then do :



gcc ntest.c -o ntest -lcurses

./ntest



If you do it again with the clear() comented out your will see the difference.



Hope this helps
 
Hi ,
When I am compling the code u have given,
I am getting the error
'EXIT_FAILURE' undeclared (first use in this function).
Instead of EXIT_FAILURE if I am writing exit(0) it is working properly.
Can you please explain me this code in short.
 
Hi,



Well theres not much to explain - it should be self-explanatory really :



First does an initscr() and exits if error, then uses printw() to write a line on the screen and calls refresh() to update display; then waits 3 seconds just for demo purposes with sleep(3). clear() clears the screen then there is another printw(), refresh(), sleep() sequence to write another line. endwin() closes the window.



Its deliberately simple because it just to demonstrate clear().



See 'man 3 ncurses' for the ncurses manual page.
EXIT_FAILURE is defined as 1 and is in stdlib.h (not stdio.h).


Regards
 
Hi,
I am very much thankful to you for the quick information provided by you.

Ifinchiam,Like a Windows OS,Is there any help for Liux(except man) (i.e. the help with example)?








 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top