/* Count chars */ #include #include int count_chars(char, char*); int main() { char *chaine = "Hello world!"; char caractere; int count; caractere = 'e'; count = count_chars(caractere, chaine); printf("Chaine: %s\n", chaine); printf("Le caractère '%c' est présent %d fois.\n", caractere, count); caractere = 'l'; count = count_chars(caractere, chaine); printf("Chaine: %s\n", chaine); printf("Le caractère '%c' est présent %d fois.\n", caractere, count); return 0; } int count_chars(char caractere, char *chaine) { int i = 0; int count = 0; while (chaine[i] != '\0') { if (chaine[i] == caractere) { count++; } i++; } return count; }