char ch;
do
{
printf("Digite aqui um caractere: ");
scanf(" %c", &ch);
} while ((ch < 'A' && ch > 'Z' ) || (ch < 'a' && ch > 'z') || ch != '.');
return ch;
I tried all sort of things on this condition and I can't make it happen. I want to return the value of "ch" when the input is [A-Z] or [a-z] or '.'.
In the condition of the loop
for example thus subexpression
is always evaluates to logical false because a character can not be at the same time less than
'A'and greater than'Z'.To simplify the condition at first rewrite it for the case when the loop should be interrupted.
The loop is interrupted when
Now write its negation
You will get
It is the same as
or
So you will have
Another approach is to use standard function
tolowerortoupperdeclared in the header<ctype.h>to simplify the condition as for exampleOr according to the remarkable idea of @Gerhardh you can also write