#include <stdio.h>

char *ft_strcapitalize(char *str) {
    int debut_mot = 1;

    char *ptr = str;

    while (*str) {
        if (debut_mot && ((*str >= 'a' && *str <= 'z') || (*str >= 'A' && *str <= 'Z'))) {
            if (*str >= 'a' && *str <= 'z') {
                *str -= 32;
            }
            debut_mot = 0;
        } else if (!((*str >= 'a' && *str <= 'z') || (*str >= 'A' && *str <= 'Z') || (*str >= '0' && *str <= '9'))) {
            debut_mot = 1;
        }

        str++;
    }

    return ptr;
}

int main() {
    char phrase[] = "salut, ca va ? 42mots quarante-deux ; cinquante+et+un";

    printf("%s\n", phrase);

    char *resultat = ft_strcapitalize(phrase);

    printf("%s", resultat);

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: