C Program to Count Vowels and Consonants in a String using a Pointer

C Program to Count Vowels and Consonants in a String using a Pointer

Program to count vowels and consonants in a string using a pointer in c; Through this tutorial, we will learn to count vowels and consonants in a string using a pointer in c.

C Program to Count Vowels and Consonants in a String using a Pointer

#include <stdio.h>

int main()
{
    char str[100];
    char *ch;
    int vowCount = 0, consCount = 0;

    printf("Please Enter String to Count Vowels and Consonants :- ");
    fgets(str, sizeof str, stdin);

    ch = str;
    
    while(*ch != '
#include <stdio.h>
int main()
{
char str[100];
char *ch;
int vowCount = 0, consCount = 0;
printf("Please Enter String to Count Vowels and Consonants :- ");
fgets(str, sizeof str, stdin);
ch = str;
while(*ch != '\0')
{
if(*ch == 'a' || *ch == 'e' || *ch == 'i' || *ch == 'o' || *ch == 'u' ||
*ch == 'A' || *ch == 'E' || *ch == 'I' || *ch == 'O' || *ch == 'U')  
{
vowCount++;
}
else
{
consCount++;
}
ch++;
}
printf("Total Vowels     = %d\n", vowCount);
printf("Total Consonants = %d\n", consCount - 1);
}
') { if(*ch == 'a' || *ch == 'e' || *ch == 'i' || *ch == 'o' || *ch == 'u' || *ch == 'A' || *ch == 'E' || *ch == 'I' || *ch == 'O' || *ch == 'U') { vowCount++; } else { consCount++; } ch++; } printf("Total Vowels = %d\n", vowCount); printf("Total Consonants = %d\n", consCount - 1); }

The output of the above c program; is as follows:

Please Enter String to Count Vowels and Consonants :- Tutsmake.com
Total Vowels     = 4
Total Consonants = 8

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *