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

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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