Below code will check whether character passed from command line is vowel or consonant.
“A”, “E”,”I”,”O”,”U” either in upper or lower case character are vowels. Other than “A”, “E”,”I”,”O”,”U” all characters between A to Z are consonant.
//Program Name: Accept a lower or Upper case character from the user from command line
//for example program name character (main.c a)
//and check whether the character is a vowel or consonant.
void main(int argc, char *argv)
//we are storing first character of second parameter in below way
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' &&ch <= 'Z'))
printf("\n\n %c is Vowel ",ch);
printf("\n\n %c is Consonant ",ch);
printf("\n\n %c is not character",ch);
Enter character to check for Vowel or Consonant: a
a is not character
a is Vowel
While running above code from command line need to pass two arguments like “program name” “character” for e.g main.c i and then press enter. Program will read second string of command line and capture first character of that string and store it in variable “ch”. In If condition it is validating whether entered character is in between lower/upper case A to Z. After successful validation it is comparing characters with vowels if not matched then it shows output as consonant.
Any character which does not belong to A to Z, Program is treating it as “invalid input”.