Count Vowels, Consonants, Digits, Spaces Dry Run in C

Count Vowels, Consonants, Digits, Spaces is an interactive C dry run visualizer from the Strings programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Count Vowels, Consonants, Digits, Spaces Program Code

#include <stdio.h>
#include <ctype.h>
int main() {
    char str[] = "Hello World 2025!";
    int vowels = 0, consonants = 0, digits = 0, spaces = 0;
    int i = 0;
    
    while(str[i] != '\0') {
        char ch = tolower(str[i]);
        
        if(ch >= 'a' && ch <= 'z') {
            if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
                vowels++;
            else
                consonants++;
        }
        else if(ch >= '0' && ch <= '9')
            digits++;
        else if(str[i] == ' ')
            spaces++;
        
        i++;
    }
    
    printf("Vowels: %d\n", vowels);
    printf("Consonants: %d\n", consonants);
    printf("Digits: %d\n", digits);
    printf("Spaces: %d\n", spaces);
    
    return 0;
}

View the complete Strings programs page.

Program Console Count Vowels, Consonants, Digits, Spaces Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.