1
I’m trying to get the user to type a symbol on input and the program recognizes whether the symbol typed was a vowel, an uppercase vowel, depending on the uppercase or other character.
For this I am comparing a string input with the arrays filled with certain vowels, consonants, etc., but prompt runs up to the input, and as soon as I insert it closes, I’m probably missing the syntax because I don’t know the C language very well.
Follows the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char vowels[] = {'a', 'e', 'i', 'o', 'u'},
upperVowels[] = {'A', 'E', 'I', 'O', 'U'},
consonants[] = {'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'},
upperConsonants[] = {'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z'},
input;
printf("Enter the symbol:\n");
scanf("%c",&input);
if (strcmp(input, vowels) == 0){
printf("vowels!");
} else if (strcmp(input, upperVowels) == 0){
printf("Upper vowels!");
} else if (strcmp(input, consonants) == 0){
printf("Consonants!");
} else if (strcmp(input, upperConsonants) == 0){
printf("Upper Consonants!");
} else {
printf("You entered another character!");
}
return 0;
}
In your vowels, upperVowels, consonants, and upperConsonants definitions you have not defined strings but an array of characters (a string is a character array with the ' 0') terminator and therefore cannot use the <string function. h> as you did. Also your input variable is defined as a single character.
– anonimo
I get it, thank you!
– user143767