Answer:
Function contains into the code asked for:
- Receives a string as an argument.
- count the number of vowels in the string and return that number.
- receives a string as an argument.
- count the number of consonants in the string and return that number.
Explanation:
//Let's call libraries
#include <stdio.h>
#include <conio.h>
//Start main
int main()
{
//*Declare functions for counting number of vowels and consonants
int vowels=0;
int consonants=0;
int all=0;
//Output need information
//Ask user to input a string
printf("what do you want to count?\n");
printf("1-the vowels.\n");
printf("2-the consonants.\n");
printf("3-all of the letters on a phrase.\n");
printf("\n");
printf("-> ");
int a;
a = getchar();
switch (a)
{
//Ask user what function they want to run
case '1':
//Call the function needed to count the vowels
printf("Introduce a phrase: ");
char textoa[1001];
scanf("%s", &textoa);
char *p;
p = textoa;
while (*p != '\0')
{
if (*p == 'a' || *p == 'e' || *p == 'i' || *p == 'o' || *p == 'u' || *p == 'A' || *p == 'E' || *p == 'I' || *p == 'O' || *p == 'U') vocales ++;
p++;
}
printf("there are %d vowels.", vowels);
break;
case '2':
//Call the function needed to count the consonants
printf("Introduce a phrase: ");
char textob[1001];
scanf("%s", &textob);
p = textob;
while (*p != '\0')
{
if (*p == 'b' || *p == 'B' || *p == 'c' || *p == 'C' || *p == 'd' || *p == 'D' || *p == 'f' || *p == 'F' || *p == 'g' || *p == 'G' || *p == 'h' || *p == 'H' || *p == 'j' || *p == 'J' || *p == 'k' || *p == 'K' || *p == 'l' || *p == 'L' || *p == 'm' || *p == 'M' || *p == 'n' || *p == 'N' || *p == 'p' || *p == 'P' || *p == 'q' || *p == 'Q' || *p == 'r' || *p == 'R' || *p == 's' || *p == 'S' || *p == 't' || *p == 'T' || *p == 'v' || *p == 'V' || *p == 'w' || *p == 'W' || *p == 'x' || *p == 'X' || *p == 'y' || *p == 'Y' || *p == 'z' ||
*p == 'Z') consonants ++;
p++;
}
printf("there are %d consonants.", consonants);
break;
case '3':
printf("Introduce a phrase: ");
char textoc[1001];
scanf("%s",&textoc);
p = textoc;
while (*p != '\0')
{
if (*p == 'a' || *p == 'e' || *p == 'i' || *p == 'o' || *p == 'u' || *p == 'A' || *p == 'E' || *p == 'I' || *p == 'O' || *p == 'U' || *p == 'b' || *p == 'B' || *p == 'c' || *p == 'C' || *p == 'd' || *p == 'D' || *p == 'f' || *p == 'F' || *p == 'g' || *p == 'G' || *p == 'h' || *p == 'H' || *p == 'j' || *p == 'J' || *p == 'k' || *p == 'K' || *p == 'l' || *p == 'L' || *p == 'm' || *p == 'M' || *p == 'n' || *p == 'N' || *p == 'p' || *p == 'P' || *p == 'q' || *p == 'Q' || *p == 'r' || *p == 'R' || *p == 's' || *p == 'S' || *p == 't' || *p == 'T' || *p == 'v' || *p == 'V' || *p == 'w' || *p == 'W' || *p == 'x' || *p == 'X' || *p == 'y' || *p == 'Y' || *p == 'z' || *p == 'Z') all ++;
p++;
}
printf("there are %d letters on the phrase.", all); break;
} getch();
}