以下注释的也是一种方法,可以采纳一下。
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<windows.h>
#include<assert.h>
int fun(char *str)
{
assert(str);
if (*str == '\0')
return 0;
return fun(str + 1) +1;
//int i = 0;
//int count = 0;
//for (i = 0; i < 10; i++)
//{
// if (str[i] == '\0')
// {
//
// break;
// }
// else
// {
// count++;
// }
//}
//printf("%d\n", count+1);
}
int main()
{
char str[] = "abcdefg";
//fun(str);
printf("%d", fun("abcdefg"));
system("pause");
return 0;
}