Code:
if (ch == 'A' || ch == 'B' || ch == 'C' || ch == 'D' || ch == 'E' || ch == 'F' ||
ch == 'G' || ch == 'H' || ch == 'I' || ch == 'J' || ch == 'K' || ch == 'L' ||
ch == 'M' || ch == 'N' || ch == 'O' || ch == 'P' || ch == 'Q' || ch == 'R' ||
ch == 'S' || ch == 'T' || ch == 'U' || ch == 'V' || ch == 'W' || ch == 'X' ||
ch == 'Y' || ch == 'Z')
How about:
Code:
if (ch >= 'A' && ch <= 'Z')
Code:
else
{
printf("\nWrong character. Try again.\n");
}
printf("\n");
return;
This code will ONLY be reached when you reach the else-branch, since all the other code is in the if-side of the code and this part has a return in each of it's if/else branch. So you can either remove the else part altogether, or you could move the printf + return into the else.
Don't use this - fflush on input files is "undefined" in the C standard. It may well work on the system you are using, but compiling your code in a different setup (different compiler or different OS) and it will do nothing useful, and since it's undefined, it allows the system to "do anything it likes", including crash. See the FAQ for a solution of "how to clear the input buffer" - although you probably want to put that AFTER your scanf() to remove any un-necessary input that came with the character you read.
Finally, it's fairly clear that you don't understand how your code works. Where do you expect the output to come from?
--
Mats