Bu cevap, konu sahibi tarafından kabul edilebilir bir cevap olarak işaretlendi.
Metotlu bir şekilde yazdımki daha kolay anlaşılabilsin. Anlamadığın yeri sorabilirsin
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void findSpecialCharacter(char srText[], char ch);
void calculateConsAndVowel(char str[]);
void calculateSentences(char str[]);
int main() {
char srText[10000],ch;
printf("Please enter the name: ");
fgets(srText,sizeof(srText),stdin);
printf("Please enter the character you want to find: ");
scanf("%c",&ch);
findSpecialCharacter(srText,ch);
calculateConsAndVowel(srText);
calculateSentences(srText);
return 0;
}
void findSpecialCharacter(char srText[], char ch){
int numberOfSpecialCharacter = 0;
for(int i=0; srText[i] != '\0'; ++i){
if(ch == srText[i]){
++numberOfSpecialCharacter;
}
}
printf("Frequency of %c => %d \n",ch,numberOfSpecialCharacter);
}
void calculateConsAndVowel(char str[]){
int numberOfConsonants = 0;
int numberOfVowels = 0;
for(int i=0; str[i] != '\n'; ++i){
str[i] = tolower(str[i]);
if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' ||
str[i] == 'o'|| str[i] == 'u'){
++numberOfVowels;
}
else if (isalpha(str[i])){
++numberOfConsonants;
}
}
printf("Count of vowels in the string you entered: => %d \n",numberOfVowels);
printf("Count of constants in the string you entered: => %d \n",numberOfConsonants);
}
void calculateSentences(char str[]){
int numberOfSentences = 1; // We start suddenly because the program doesn't count the first word
for(int i = 0; i < strlen(str); i++){
if(str[i] == ' '){
++numberOfSentences;
}
}
printf("There are %d words in total in the sentence entered.",numberOfSentences);
}