S SmartDocs
Serie: C Programming Language c 53 líneas · Actualizado 2026-02-03

solution_6_3_vowel_counter.c

C Programming Language/solutions/intermediate/week6/solution_6_3_vowel_counter.c

/**
 * Solution 6.3: Vowel Counter
 * Week 6 - Arrays and String Basics
 * 
 * Description: Count vowels in a string
 */

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int countVowels(char str[]) {
    int count = 0;
    int len = strlen(str);
    
    for (int i = 0; i < len; i++) {
        char ch = tolower(str[i]);
        if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
            count++;
        }
    }
    
    return count;
}

int main() {
    char str[100];
    
    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);
    
    // Remove newline character
    str[strcspn(str, "\n")] = '\0';
    
    int vowels = countVowels(str);
    
    printf("Number of vowels: %d\n", vowels);
    
    char *newstr;
    /* str = "Xyz abc Mnd abc QPR abc" */
    newstr = str;
    do {
        printf("New string: %s\n", newstr); /* print the new string */
        newstr = strstr(str, "abc");
        newstr = strstr(newstr + 3, "abc");
        newstr = strstr(newstr + 3, "abc");
    } while (newstr != NULL);
    

    
    
    return 0;
}

Artículos relacionados

C Programming Language c Actualizado 2026-02-03

bitwise_operations_advanced.c

bitwise_operations_advanced.c — c source code from the C Programming Language learning materials (C Programming Language/additional/advanced_topics/bitwise_operations_advanced.c).

Leer artículo →
C Programming Language c Actualizado 2026-02-03

huffman_coding_complete.c

huffman_coding_complete.c — c source code from the C Programming Language learning materials (C Programming Language/additional/advanced_topics/huffman_coding_complete.c).

Leer artículo →
C Programming Language c Actualizado 2026-02-03

recursion_advanced.c

recursion_advanced.c — c source code from the C Programming Language learning materials (C Programming Language/additional/algorithms/recursion_advanced.c).

Leer artículo →
C Programming Language c Actualizado 2026-02-03

sorting_algorithms_complete.c

sorting_algorithms_complete.c — c source code from the C Programming Language learning materials (C Programming Language/additional/algorithms/sorting_algorithms_complete.c).

Leer artículo →
C Programming Language c Actualizado 2026-02-03

binary_trees_complete.c

binary_trees_complete.c — c source code from the C Programming Language learning materials (C Programming Language/additional/data_structures/binary_trees_complete.c).

Leer artículo →
C Programming Language c Actualizado 2026-02-03

linked_lists_complete.c

linked_lists_complete.c — c source code from the C Programming Language learning materials (C Programming Language/additional/data_structures/linked_lists_complete.c).

Leer artículo →