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 C program to count the number of vowels, consonants, digits and symbols using pointers.
Runtime Input :
1=>see-programming
Output :
No. of vowels: 5
No. of consonants: 9
No. of digits: 1
No. of symbols: 3
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
void getCounters(char message[],int* noVowels,int* noConsonants,int* noDigits,int* noSymbols){
int i=0;
do {
if (tolower(message[i]) == 'a' ||
tolower(message[i]) == 'e' ||
tolower(message[i]) == 'i' ||
tolower(message[i]) == 'o' ||
tolower(message[i]) == 'u') {
(*noVowels)++;
} else if ((tolower(message[i]) >= 'a' && tolower(message[i]) <= 'z')) {
(*noConsonants)++;
} else if (message[i] >= '0' && message[i] <= '9') {
(*noDigits)++;
} else{
(*noSymbols)++;
}
i++;
}while(message[i] != '\0');
}
void main( void){
char message[1000];
int noVowels=0;
int noConsonants=0;
int noDigits=0;
int noSymbols=0;
printf("Enter the message: ");
gets(message);
getCounters(message,&noVowels,&noConsonants,&noDigits,&noSymbols);
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);
getchar();
getchar();
}
Comments
Leave a comment