ncurses troubles
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > ncurses troubles




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    ncurses troubles  
mr_semantics@hotmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-21-05 12:48 PM

I have been fiddling with ncurses, particularly with the material found
in
the book 'Beginning Linux Programming, 3rd edition' - anyway, there is
a
program on page 216 that I can't get to work properly.  Here is the
code
that I believe is causing the trouble:


move(9, 10);
printw("%s", "Password: ");
refresh();

cbreak();
noecho();

memset(password, '\0', sizeof(password));
while (i < PW_LEN) {
password[i] = getch();
move(9, 20 + i);
addch('*');
refresh();
if (password[i] == '\n') {
break;
}
if (strcmp(password, real_password) == 0) {
break;
}
i++;
}

echo();
nocbreak();

move(11, 10);
if (strcmp(password, real_password) == 0) {
printf("%s", "Correct");
} else {
printf("%s", "Wrong");
}

refresh();
endwin();

return 0;
}

...in particular, the program executes (seemingly) properly until the
statements:
if (strcmp(password, real_password) == 0) {
printf("%s", "Correct");
} else {
printf("%s", "Wrong");
}

It does not print out anything at all.  I enter the password, and then
the
program terminates.  I have stepped through the program with a
debugger,
and when I enter the correct password, it indeed says 'Correct', but
only
in the debugger.  Any help would be appreciated.

Rob Somers






[ Post a follow-up to this message ]



    Re: ncurses troubles  
Thomas Dickey


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-21-05 12:48 PM

mr_semantics@hotmail.com wrote:

> ...in particular, the program executes (seemingly) properly until the
> statements:
> if (strcmp(password, real_password) == 0) {
>                 printf("%s", "Correct");
>         } else {
>                 printf("%s", "Wrong");
>         }

> It does not print out anything at all.  I enter the password, and then the
> program terminates.  I have stepped through the program with a debugger, a
nd
> when I enter the correct password, it indeed says 'Correct', but only in t
he
> debugger.  Any help would be appreciated.

Normally you'd use printw() rather than printf() to write to the screen.
While it is possible to mix the two, you have to keep in mind that (n)curses
doesn't know what was done with the printf.  The refresh() does nothing,
since there were no changes to stdscr since the last refresh() call.

Adding a fflush(stdout) after the printf's will get the text displayed,
but using printw is preferable, since then (n)curses will know where the
cursor is.

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:21 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register