In online journal system, the user has to give detail information about their abstract of the manual script before upload of source document. The abstract submitted by the author should not more than 300 words. The journal system uses program to count the number of vowels, consonants, digits and symbols in a given paragraph. Write a program to count the number of vowels, consonants, digits and symbols using pointers as reference to the function.
Runtime Input :
1=>see-programming.blogspot.com
Output :
No. of vowels: 8
No. of consonants: 17
No. of digits: 1
No. of symbols: 1
Others: 4
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
void getCounters(char text[],int* noVowels,int* noConsonants,int* noDigits,int* noSymbols,int* noOthers);
void main( void){
char text[5000];
int noVowels=0;
int noConsonants=0;
int noDigits=0;
int noSymbols=0;
int noOthers=0;
printf("Enter the text: ");
gets(text);
getCounters(text,&noVowels,&noConsonants,&noDigits,&noSymbols,&noOthers);
printf("No. of vowels: %d\n",noVowels);
printf("No. of consonants: %d\n",noConsonants);
printf("No. of digits: %d\n",noDigits);
printf("No. of symbols: %d\n",noSymbols);
printf("Others: %d\n\n",noOthers);
getchar();
getchar();
}
void getCounters(char text[],int* noVowels,int* noConsonants,int* noDigits,int* noSymbols,int* noOthers){
int noVowelsCounter=0;
int noConsonantsCounter=0;
int noDigitsCounter=0;
int noSymbolsCounter=0;
int noOthersCounter=0;
int i,j;
for (i = 0; text[i] != '\0'; ++i) {
if (tolower(text[i]) == 'a' ||
tolower(text[i]) == 'e' ||
tolower(text[i]) == 'i' ||
tolower(text[i]) == 'o' ||
tolower(text[i]) == 'u') {
noVowelsCounter++;
} else if ((text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'A' && text[i] <= 'Z')) {
noConsonantsCounter++;
} else if (text[i] >= '0' && text[i] <= '9') {
noDigitsCounter++;
} else if (text[i] == '-'){
noSymbolsCounter++;
}else{
noOthersCounter++;
}
}
*noVowels=noVowelsCounter;
*noConsonants=noConsonantsCounter;
*noDigits=noDigitsCounter;
*noSymbols=noSymbolsCounter;
*noOthers=noOthersCounter;
}
Comments
Leave a comment