For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > August 2005 > ncurses troubles









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author ncurses troubles
Rob Somers

2005-08-24, 9:56 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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com