Chapter:

Strings-in-C-programming-

Write a C program to find total number of vowels and consonants in a string.

Without using pointers:

/**
 * C program to count total number of vowel or consonant in a string using switch case
 */

#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100 // Maximum string size

int main()
{
    char str[MAX_SIZE]; 
    int i, len, vowel, consonant;

    /* Input strings from user */
    printf("Enter any string: ");
    gets(str);


    vowel = 0;
    consonant = 0;
    len = strlen(str);

    for(i=0; i<len; i++)
    {
        if((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z'))
        {
            switch(str[i])
            {
                case 'a':
                case 'e':
                case 'i':
                case 'o':
                case 'u':
                case 'A':
                case 'E':
                case 'I':
                case 'O':
                case 'U':
                    vowel++;
                    break;
               ....
Show More

All Chapters

View all Chapter and number of question available From each chapter from C-programming-