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.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 getStat(char paragraphText[],int* vowels,int* consonants,int* digits,int* symbols,int* others);
void main( void){
char paragraphText[5000];
int vowels=0;
int consonants=0;
int digits=0;
int symbols=0;
int others=0;
printf("Enter the paragraph text: ");
gets(paragraphText);
getStat(paragraphText,&vowels,&consonants,&digits,&symbols,&others);
printf("No. of vowels: %d\n",vowels);
printf("No. of consonants: %d\n",consonants);
printf("No. of digits: %d\n",digits);
printf("No. of symbols: %d\n",symbols);
printf("Others: %d\n\n",others);
getchar();
getchar();
}
void getStat(char paragraphText[],int* vowels,int* consonants,int* digits,int* symbols,int* others){
int i=0;
while(paragraphText[i] != '\0') {
if (tolower(paragraphText[i]) == 'a' || tolower(paragraphText[i]) == 'e' || tolower(paragraphText[i]) == 'i' ||
tolower(paragraphText[i]) == 'o' || tolower(paragraphText[i]) == 'u') {
(*vowels)++;
} else if ((tolower(paragraphText[i]) >= 'a' && tolower(paragraphText[i]) <= 'z')) {
(*consonants)++;
} else if (paragraphText[i] >= '0' && paragraphText[i] <= '9') {
(*digits)++;
} else if (paragraphText[i] == '-'){
(*symbols)++;
}else{
(*others)++;
}
i++;
}
}
Comments
Leave a comment