VaultBy ENSAMIENParrainage
C25 lines

tp5-ex3.c

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>
#include <ctype.h>

int main() {
    char CH[101];
    int ABC[26] = {0};
    char *PCH = CH;
    int i;
    printf("Entrez une chaine (max 100 caractères) :\n");
    fgets(CH, 101, stdin);
    while (*PCH != '\0') {
        if (isalpha(*PCH)) {
            char c = tolower(*PCH);
            ABC[c - 'a']++;
        }
        PCH++;
    }
    printf("Occurrences des lettres :\n");
    for (i = 0; i < 26; i++) {
        if (ABC[i] > 0) {
            printf("%d fois la lettre '%c'\n", ABC[i], 'A' + i);
        }
    }
    return 0;
}

    Type at least 2 letters. ↑ ↓ to move, Enter to open.