标签:love you while printf clu string lse r++ str 递归
#include<stdio.h>
#include<string.h>
int my_strlen(char* str)
{
int count = 0;
while (*str != ‘\0‘)
{
count++;
*str++;
}
return count;
}
int main()
{
char arr[] = { "i love you" };
int len = my_strlen(arr);
printf("%d", len);
}
#include<stdio.h>
int my_strlen(char* str)
{
if (*str != ‘\0‘)
return my_strlen(str+1) + 1;
else
return 0;
}
int main()
{
char arr[] = { "i love you" };
int len = my_strlen(arr);
printf("%d", len);
}
C语言习题【5】strlen的模拟(递归和非递归分别实现strlen)
标签:love you while printf clu string lse r++ str 递归
原文地址:https://blog.51cto.com/14737345/2479828