一,求ch字符串长度,递归实现
参考代码:
int strlength(char* p) {
int k = 0;
if (*p == '\0')return 0;
else return 1 + strlength(p + 1);
}
int main() {
char ch[100] = "good";
int len;
len = strlength(ch);
printf("字符串的长度%d", len);
return 0;
}
运行结果:
二,把ch中某个字符小写转大写,返回个数
参考代码:
int replace(char* p, char c) {
int k = 0;
while (*p) {
if (*p == c) { *p = *p - 32; k++; }
p++;
}
return k;
}
int main() {
char ch[100] = "good";
int count = 0;
count = replace(ch, 'o');
printf("%s", ch);
return 0;
}