strlen function using recursion in c

后端 未结 4 1382
离开以前
离开以前 2021-01-26 11:17

I\'m kida new to the recursion subject and i\'ve been trying to write the \"strlen\" function using recurion, thats what i tried:

int strlen ( char str[], int i         


        
4条回答
  •  醉酒成梦
    2021-01-26 12:00

    If you want to keep the same prototype as strlen does. This is how i see a strlen with recursion.

    size_t strlen(char *str)
    {
        static int i = 0;
    
        if (*str != '\0')
        {
            i++;
            return ft_strlen(++str);
        }
        return i;
    }
    

    I know it's not the best way to do it. Just my implementation.

提交回复
热议问题