Une chaîne C cache un '\0' à la fin, qui veut dire « c’est fini ici ». Sans strlen, écris my_strlen(s) : compte depuis le début, arrête-toi au '\0' et renvoie le nombre compté. Par exemple, "hello" donne 5, un espace compte comme un caractère, et la chaîne vide "" donne 0.
my_strlen("hello")→5my_strlen("")→0my_strlen("a b c")→5int my_strlen(const char *s)int my_strlen(const char *s) {
int n = 0;
// ton code ici: tant qu’on n’a pas atteint '\0', ajoute 1 à n
return n;
}
Exécuter teste les exemples. Quand ils sont bons, appuie sur Envoyer.