This is my first post ever, so please bear with me as I do not quite understand how to post my code the way the forum accepts it.
As the title shows, I am trying to find the number of vowels, lowercase, and specific occurrence of each letter in a manually inputted string.
Here is my code:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int calVowel(char myStr[]);
int calUppercase(char myStr[]);
int calDigit(char myStr[]);
int calChar(char myStr[], char myChar);
int main()
{
char mystring[100];
printf("Type your string:\n");
gets(mystring);
int myVowel = calVowel(mystring);
printf("Total number of vowels are %i", myVowel);
int myUppercase = calUppercase(mystring);
printf("Total number of uppercase are %i", myUppercase);
int myDigit = calDigit(mystring);
printf("Total number of digits are %i", myDigit);
return 0;
}
// function to calculate the total number of vowel characters
// input: a string
// output: the number of vowel characters
int calVowel(char myStr[])
{
int countVowel = 0;
int vowelIdx = 0;
while (myStr[vowelIdx] != '\0')
{
if ((myStr[vowelIdx] == 'a') || (myStr[vowelIdx] == 'e') || (myStr[vowelIdx] == 'i') || (myStr[vowelIdx] == 'o') || (myStr[vowelIdx] == 'u'))
{
countVowel++;
}
vowelIdx++;
}
return (countVowel);
}
// function to calculate the total number of uppercase characters
// input: a string
// output: the number of uppercase characters
int calUppercase(char myStr[])
{
int size = 2;
int countUppercase = 0;
for (int calUppercase = 0; calUppercase <= size; calUppercase++)
{
char U = myStr[calUppercase];
if (toupper(U) == 1)
{
countUppercase++;
}
}
return countUppercase;
}
// function to calculate the total number of digital characters
// input: a string
// output: the number of digit
int calDigit(char myStr[])
{
int countDigit = 0;
for (int calDigit = 0; calDigit <= size; calDigit++)
{
char D = myStr[calDigit];
if (isdigit(D) == 1)
{
countDigit++;
}
}
return countDigit;
}
// function to calculate the total number of a specific characters in a string
// input: a string, a character
// output: the number of the character in the string
int calChar(char myStr[], char myChar)
{