In this C program, we are counting the total number of vowels and consonants of a string using pointer.
Here, we are reading a string and assigning its base address to the character pointer, and to check characters are vowels or consonants, we will check and count each character one by one by increasing the pointer.
/*C program to count vowels and consonants in a string using pointer.*/
printf("Enter a string: ");
//assign address of str to ptr
if(*ptr=='A' ||*ptr=='E' ||*ptr=='I' ||*ptr=='O' ||*ptr=='U' ||*ptr=='a' ||*ptr=='e' ||*ptr=='i' ||*ptr=='o' ||*ptr=='u')
//increase the pointer, to point next character
printf("Total number of VOWELS: %d, CONSONANT: %d\n",cntV,cntC);
Enter a string: This is a test string
Total number of VOWELS: 5, CONSONANT: 16
total answers (1)
start bookmarking useful questions and collections and save it into your
own study-lists, login now to start creating your own collections.