用C语言递归函数strlength实现求字符串长度和将ch某个字符小写转成大写,返回个数---------(C每日一编程)
发布时间:2023年12月23日
一,求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;
}
运行结果:

以上仅供参考。

文章来源:https://blog.csdn.net/weixin_64545778/article/details/135133360
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:chenni525@qq.com进行投诉反馈,一经查实,立即删除!