That program output (the chr is not a vowel ) everytime !! even if it's vowel

#include <stdio.h>
#include <conio.h>

int main()
{
    char ch;

    printf("Input a character\n");
    scanf_s("%c", &ch);

    switch (ch)
    {
    case 'a':
    case 'A':
    case 'e':
    case 'E':
    case 'i':
    case 'I':
    case 'o':
    case 'O':
    case 'u':
    case 'U':
        printf("%c is a vowel.\n", ch);
        break;
    default:
        printf("%c is not a vowel.\n", ch);
    }


    _getch();
    return 0;
}

Did you try to use the getchar() function?

I think there is no error with getch function it works fine , the problem in the structre of siwtch statment because it gives me vowel everytime .. and getch works because i have to press any key to continue .

My compiler does not support scanf_s (it's a Microsoft extension I think) but if I change your scanf_s to a scanf call it works as expected.

So I looked up scanf_s in the Microsoft help and it said

Unlike scanf and wscanf, scanf_s and wscanf_s require the buffer size to be specified for all input parameters of type c, C, s, S, or string control sets that are enclosed in []. The buffer size in characters is passed as an additional parameter immediately following the pointer to the buffer or variable. For example, if you are reading a string, the buffer size for that string is passed as follows:

and then gave this example of reading a char

char c;
scanf_s("%c", &c, 1);

Next time try reading the manual.

commented: Great! +15

It works under my compiler too(gcc 4.7 debian), i replaced scanf_s with scanf, and it works perfectly!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.