用递归实现strlen函数

来源:互联网 发布:大数据运维工作内容 编辑:程序博客网 时间:2024/06/05 16:05
#include<stdio.h>#include<windows.h>int mystrlen(char *string){    if ((*string) == '\0')    {        return 0;     }    else    {        return 1 + mystrlen(++string);    }}int main(){    char *ch1 = "abcdefg";    char ch2[10] = { '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 0;}

这里写图片描述

原创粉丝点击