天天看點

用遞歸實作strlen函數

#include<stdio.h>
#include<windows.h>

int mystrlen(char *string)
{
    if ((*string) == '\0')
    {
        return ;
     }
    else
    {
        return  + mystrlen(++string);
    }
}

int main()
{
    char *ch1 = "abcdefg";
    char ch2[] = { 'a','b','c','d','e','f','g'};
    printf("the strlen of ch1 is %d\n", mystrlen(ch1));
    printf("the strlen of ch2 is %d\n", mystrlen(ch2));
    system("pause");
        return ;
}
           
用遞歸實作strlen函數

繼續閱讀