+ 2
check char in C
// the app should read one character scanf("%c", &character); // if the user input is longer as one character, or a number which is outside of my if-definition // the the code should reask the input if(c==longerThenOneChar && c <65 && c>90) // wrong input, please input a new char scanf("%c", &character); // how can i check this
4 Antworten
+ 2
how i find out, if c is longer then one char?
+ 1
You cannot test if its longer than one char this way, because you are only reading the first char. To do that you will need to read until the end of the input, then test if its more than 1 char. Or just test for a second char.
+ 1
Check this:
https://code.sololearn.com/cApMl9zk1PUO/#c
0
Use do{ } while();
do {
scanf("%c", &character);
while(c == longerThenOneChar || c <65 || c>90) ;
if you want to show messages asking for input:
e = 0;
do{
if (e > 0) {
printf("error. input again");
} else {
printf("Input character");
e = 1;
}
scanf("%c", &character);
}while(c == longerThenOneChar || c <65 || c>90) ;
...just one of many versions... :)