fonction recursive successeur nombre chaine de caractere en c

Here is a recursive function in C that counts the number of characters in a string:

#include <stdio.h>

int countChars(char* str) {
    if (*str == '\0') {
        return 0;
    } else {
        return 1 + countChars(str + 1);
    }
}

int main() {
    char str[] = "Hello, World!";
    int count = countChars(str);
    printf("The number of characters in the string is: %d\n", count);
    return 0;
}

This recursive function countChars takes a pointer to a string str as input. It checks if the current character is the null character '\0', which marks the end of the string. If it is, the function returns 0, indicating that there are no more characters to count. Otherwise, it recursively calls itself with the next character in the string by incrementing the pointer str + 1 and adds 1 to the result. This process continues until the end of the string is reached.

In the main function, a sample string "Hello, World!" is declared and passed to the countChars function. The result is then printed to the console.

Please note that this is just one possible implementation of a recursive function to count the number of characters in a string, and there are multiple ways to achieve the same result.