#include <stdio.h> void fun(char s[], char t) { int i = 0; while (s[i]) { if (s[i] == t) s[i] = t - 'a' + 'A'; i++; } } int main() { char str[100] = "abcdefg", c = 'd'; fun(str, c); printf("%s\n", str); return 0; }解答程序
时间: 2024-01-18 18:04:46 浏览: 75
这个程序的功能是将字符串中所有与给定字符相同的小写字母转换为大写字母。具体来说,函数`fun`接受两个参数,一个字符串`s`和一个字符`t`,函数会遍历字符串`s`中的所有字符,如果字符与`t`相同且为小写字母,就将其转换为对应的大写字母。函数`main`中定义了一个字符串`str`和一个字符`c`,将字符串`"abcdefg"`赋值给`str`,将字符`'d'`赋值给`c`,然后调用`fun(str, c)`函数,最后打印输出字符串`s`的值。执行结果为:
```
abCDefg
```
其中,字符`'d'`被转换成了大写字母`'D'`。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)