#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
int Strlen1(char* str) {//递归
if (*str == '\0') {
return 0;
}
else {
return Strlen1(str + 1) + 1;
}
}
//************
int Strlen2(char* str) {//非递归
int n = 0;
while (*str != '\0') {
++str;
++n;
}
return n;
}
void main() {
char str[30] = { 0 };
printf("请输入一串字符\n");
scanf("%s", &str);
printf("递归判断字符串长度是:%d\n", Strlen1(str));
printf("非递归判断字符串长度是:%d\n", Strlen2(str));
system("pause");
}
【