Hello, I'm working on a program to determine if it's a capital letter, a lowercase letter, or an English letter by typing 5 characters, but when I try to repeat it with a for sentence, it keeps saying else is not an English letter, but I can't even do it 5 times.
int main() {
char c;
for (int i = 0; i < 5; i++) {
scanf_s("%c", &c);
if (c >= 'a' && c <= 'z') {
printf ("lower case"\n");
}
else if (c >= 'A' && c <= 'Z') {
printf ("uppercase letters").\n");
}
else {
printf ("Not English\n");
}
}
return 0;
The workaround is to use the scanf_s function by adding "%c"
to the first column, such as "%c"
.
Read the previously answered article below why this is happening.
https://hashcode.co.kr/questions/12755/
#include <stdio.h>
int main()
{
char c;
for (int i = 0; i < 5; i++) {
scanf_s(" %c", &c, 1);
if (c >= 'a' && c <= 'z')
printf ("lower case"\n");
else if (c >= 'A' && c <= 'Z')
printf ("uppercase letters").\n");
else
printf ("Not English\n");
}
return 0;
}
© 2024 OneMinuteCode. All rights reserved.