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 ]
|