A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to count vowels and consonants in a string using pointer
Q:

C program to count vowels and consonants in a string using pointer

0

C program to count vowels and consonants in a string using pointer

In this C program, we are counting the total number of vowels and consonants of a string using pointer.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.*/
#include <stdio.h>
int main()
{
    char str[100];
    char *ptr;
    int  cntV,cntC;
     
    printf("Enter a string: ");
    gets(str);
     
    //assign address of str to ptr
    ptr=str;
     
    cntV=cntC=0;
    while(*ptr!='\0')
    {
        if(*ptr=='A' ||*ptr=='E' ||*ptr=='I' ||*ptr=='O' ||*ptr=='U' ||*ptr=='a' ||*ptr=='e' ||*ptr=='i' ||*ptr=='o' ||*ptr=='u')
            cntV++;
        else
            cntC++;
        //increase the pointer, to point next character
        ptr++;
    }
     
    printf("Total number of VOWELS: %d, CONSONANT: %d\n",cntV,cntC);        
    return 0;
}

Output

Enter a string: This is a test string
Total number of VOWELS: 5, CONSONANT: 16

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now