0

im new to coding so please forgive me if there's something basic i keep missing.

#include <stdio.h>
int main(){
    char ch;
    int x;
    printf("How many letters do you want to check?:");
    scanf("%d",&x);
    
    for (int i=1 ;i<=x; i+=1){
        printf("Enter character:");
        scanf("%c",&ch);
        if (ch>='a' && ch<='z'){
         printf("LOWER CASE CHARACTER");
        }
        else if (ch>='A' && ch<='Z'){
            printf("UPPERCASE CHARCTER");
        }
        else{
            printf("NOT A VALID CHARACTER");
        }
    }
printf("\n Thanks");
return 0;
}

so this is my code and this is the output: it adds the not a valid charcter? is pressing enter count as a character idk

  • Yes, pressing Enter counts as a `'\n'` character. Does that answer your question? – Thomas Oct 04 '22 at 14:09
  • Please copy and paste the output into your question, instead of linking to a screenshot. – Thomas Oct 04 '22 at 14:09
  • Yes, the [enter] key produces a character (a newline, `'\n'`) in the input. Many `scanf` directives will skip over that as well as spaces, tabs, *etc*., but the `%c` will not do so. `%c` is specifically intended to be able to read any character, including whitespace. – John Bollinger Oct 04 '22 at 14:10
  • `scanf("%c",&ch);` -> `scanf("%c",&ch); getchar();` probably solves all problems. Also see the linked duplicate. – Lundin Oct 04 '22 at 14:11

0 Answers0