problem with console app
-
here is a relevent snippets:
TCHAR buf[20];
fdwMode = ENABLE_LINE_INPUT | //ReadConsole() should wait and read
// characters until ENTER is pressed
ENABLE_ECHO_INPUT | // show characters as you type
ENABLE_PROCESSED_INPUT; // let system process all
// control keystrikes
SetConsoleMode(hStdin, fdwMode) ;fdwMode = ENABLE_PROCESSED_OUTPUT;
SetConsoleMode(hStdout, fdwMode);while (1)
{
WriteConsole(hStdout, "\npress [1] for codepage: ", 25, &ch, NULL);
ReadConsole(hStdin,buf,1,&ch,NULL);
buf[ch]='\0';
FlushConsoleInputBuffer(hStdin);
WriteConsole(hStdout, buf, 3, &ch, NULL);
}the problem is that the first time while executes everything is ok: i get on screen:
press [1] for codepage:
i enter 1 and press enter then it prints the character. from this point something strange happens... while loop continue to execute two more times despite the fact that ReadConsole() should wait for input... anyone understand where is the problem?
-
here is a relevent snippets:
TCHAR buf[20];
fdwMode = ENABLE_LINE_INPUT | //ReadConsole() should wait and read
// characters until ENTER is pressed
ENABLE_ECHO_INPUT | // show characters as you type
ENABLE_PROCESSED_INPUT; // let system process all
// control keystrikes
SetConsoleMode(hStdin, fdwMode) ;fdwMode = ENABLE_PROCESSED_OUTPUT;
SetConsoleMode(hStdout, fdwMode);while (1)
{
WriteConsole(hStdout, "\npress [1] for codepage: ", 25, &ch, NULL);
ReadConsole(hStdin,buf,1,&ch,NULL);
buf[ch]='\0';
FlushConsoleInputBuffer(hStdin);
WriteConsole(hStdout, buf, 3, &ch, NULL);
}the problem is that the first time while executes everything is ok: i get on screen:
press [1] for codepage:
i enter 1 and press enter then it prints the character. from this point something strange happens... while loop continue to execute two more times despite the fact that ReadConsole() should wait for input... anyone understand where is the problem?
cpeed wrote: anyone understand where is the problem? Considering you only request one char, and '1' + CR + LF is three chars...
-
cpeed wrote: anyone understand where is the problem? Considering you only request one char, and '1' + CR + LF is three chars...