Take input and filter the string starting with a given alphabet

PHOTO EMBED

Sun Aug 25 2024 11:47:37 GMT+0000 (Coordinated Universal Time)

Saved by @Xyfer

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

int main() {
    int n;
    char words[15][101]; // Array to store up to 15 words of max length 100 characters
    char letter;
    int count = 0;

    scanf("%d", &n);

    // Input each word into the array
    for (int i = 0; i < n; ++i) {
        scanf("%s", words[i]);
    }

    // Input the letter to check
    scanf(" %c", &letter);

    // Convert letter to lowercase (if it's uppercase)
    letter = tolower(letter);

    // Count words that start with the specified letter
    for (int i = 0; i < n; ++i) {
        if (words[i][0] == letter) {
            count++;
        }
    }
    
    printf("%d\n", count);
    return 0;
}
content_copyCOPY