I want a user to enter a char. I want to filter what they enter and take only the first char they type.
int main(){
while (true){
char n = readOption();
cout << n << std::endl;
}
return 0;
}
char readOption() {
char input = '\0';
while (input != '\n') {
input = cin.get();
if (isalpha(input)) {
break;
}
}
return toupper(input);
}
If I enter 13@ jkjoi
, the console prints.
J
K
J
O
I
I only want it to print J
. Why is it printing the other letters as well?