PL said:
I read password from the console with _getcch to display no echo. The
problem is that I don't know how to flush extended char and ignore them,
like control+A, ...
In fact, I want to detect the Ctrl+C sequence in order to stop the input.
How can I do that ?
thanks
As Martin Dicko pointed out, _getcch is not Standard C. However, the
signal() function is in the standard. Your program is probably receiving
the signal represented by the macro SIGINT (in <signal.h>) when you
type Ctrl+C (the exact behavior of your console is platform-specific).
To ignore SIGINT:
#include <signal.h>
#include <stdio.h>
int main()
{
void (*old_handler)(int);
old_handler = signal(SIGINT, SIG_IGN);
if(old_handler == SIG_ERR)
{
perror("signal");
exit(1);
}
exit(0);
}
To flush out other control characters, you need to find out what
numerical values they correspond to on your system. A test program to
help you figure this out:
#include <stdio.h>
int main()
{
while(!feof(stdin) && !ferror(stdin))
printf("%d\n", getchar());
exit(0);
}
Simply type in control characters and make a note of the numbers that
come out. If your console is line-buffered, the program won't do anything
until you press Enter, then the numerical values for everything you typed,
including the Enter key, will print. Then the program waits for another
line of input.