LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-21-2010, 09:53 PM   #1
nabat1
LQ Newbie
 
Registered: Apr 2010
Posts: 4

Rep: Reputation: 0
C and ncurses on ubuntu linux.


See the example below, please. My question is this (ncurses in C): If I don't write code like this with the getch() under comment /* Write to each window */ , it doesn't show anything. Otherwise, works fine.
Also, some other question, in C and ncurses, it is like touchwin() has no effect it should has. The second example I mean, it doesn't work like both the main window and help can be switched among the work properly. I run on Ubuntu 9.10.

EXAMPLE 1.
#include <ncurses.h>
#include <stdlib.h>

void bomb(void);

int main(void)
{
WINDOW *a,*b,*c,*d;
int maxx,maxy,halfx,halfy;

initscr();

/* calculate window sizes and locations */
getmaxyx(stdscr,maxy,maxx);
halfx = maxx >> 1;
halfy = maxy >> 1;
/* create four windows to fill the screen */
if( (a = newwin(halfy,halfx,0,0)) == NULL) bomb();
if( (b = newwin(halfy,halfx,0,halfx)) == NULL) bomb();
if( (c = newwin(halfy,halfx,halfy,0)) == NULL) bomb();
if( (d = newwin(halfy,halfx,halfy,halfx)) == NULL) bomb();

/* Write to each window */
getch(); /*-----------------THIS--------------------------*/
mvwaddstr(a,0,0,"This is window A\n");
wrefresh(a);
mvwaddstr(b,0,0,"This is window B\n");
wrefresh(b);
mvwaddstr(c,0,0,"This is window C\n");
wrefresh(c);
mvwaddstr(d,0,0,"This is window D\n");
wrefresh(d);
getch();

endwin();
return 0;
}

void bomb(void)
{
addstr("Unable to allocate memory for new window.\n");
refresh();
endwin();
exit(1);
}




**********************************************************************

EXAMPLE 2.

#include <ncurses.h>

void showhelp(void);

WINDOW *help;

int main(void)
{
int ch;

initscr();

/* build help menu */
if((help = newwin(0,0,0,0)) == NULL)
{
addstr("Unable to allocate window memory\n");
endwin();
return(1);
}
mvwaddstr(help,6,32,"Help menu Screen");
mvwaddstr(help,9,28,"Press the ~ key to quit");
mvwaddstr(help,12,28,"Press ENTER to go back");

/* now start the program loop */

addstr("Typer Program\n");
addstr("Press + for help:\n\n");
refresh();
noecho();
do
{
ch = getch();
refresh();
if(ch == '+')
showhelp();

else
addch(ch);
} while (ch != '~');

endwin();
return 0;
}

void showhelp(void)
{
touchwin(help);
wrefresh(help);
getch(); /* wait for key press */
touchwin(stdscr);
refresh();
}
 
Old 08-21-2010, 10:20 PM   #2
nabat1
LQ Newbie
 
Registered: Apr 2010
Posts: 4

Original Poster
Rep: Reputation: 0
forgot to say I use virtual box 3.0.8. Other thing, if remove both getch and add wgetch(d) /*for example*/ it works. (or wgetch in second example), both work.
 
Old 09-19-2010, 10:04 AM   #3
harryhaller
Member
 
Registered: Sep 2004
Distribution: Slackware-14.2
Posts: 468

Rep: Reputation: Disabled
I can't answer your question, but I advise you to wrap up your code in
[ CODE ] ...[ /CODE ] tags, otherwise others will, rightly, get annoyed at having to read the code in its present unformatted form.

I wrote [ CODE ] with blanks so that you can read them. They are normally without blanks, but posting them would end up with something like this
Code:
 the polite way to present code in your posts
.

Last edited by harryhaller; 09-19-2010 at 10:05 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cannot get ncurses to delete a char with '\b' on screen in linux (c++) Mogget Programming 6 01-07-2010 03:39 PM
how to print text in color by ncurses without opening a ncurses window Greatrebel Programming 0 12-20-2006 09:15 AM
Linux NCurses and Ascii questions the_darkside_986 Programming 1 03-01-2006 09:01 AM
ncurses-5.2-28 conflicts with file from package ncurses-5.2-12 tubby Linux - Software 4 06-16-2002 12:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration