函数fun的功能是:将s所指字符串中下标为奇数的字符删除。串中剩余字符形成一个新串放在t所指的数组中。 例如,当s所指字符串:"ABCDEFGHIJK"时,t所指的数组的内容应是:"ACEGIK"。
时间: 2024-06-01 13:12:30 浏览: 14
函数fun的代码如下:
void fun(char *s, char *t) {
int i, j = 0;
for (i = 0; s[i] != '\0'; i++) {
if (i % 2 == 0) {
t[j++] = s[i];
}
}
t[j] = '\0';
}
这个函数会遍历输入的字符串s,将下标为奇数的字符删除,然后将剩余的字符存放在t所指的数组中。输出的结果就是题目中所示的ACEGIK。
相关问题
函数fun的功能是:将s所指字符串中下标为偶数的字符删除,剩余字符形成的新串放在t所指数组中
以下是函数fun的C语言代码实现:
```c
void fun(char *s, char *t) {
int i = 0, j = 0;
while (s[i] != '\0') {
if (i % 2 == 1) {
t[j++] = s[i];
}
i++;
}
t[j] = '\0';
}
```
函数中使用了两个指针i和j分别指向字符串s和数组t的下标。在while循环中,如果i是奇数下标,则将s[i]复制到t[j]中,j自增1。最后在t[j]处添加字符串结束符'\0'。
c语言解决函数fun的功能是:将s所指字符串下标为奇数的字符删除,串中剩余字符形成的新串放在t所指的数组中 并返回 t所指的字符串。
以下是一个C语言函数fun的实现,可以将输入字符串s中下标为奇数的字符删除,并将结果存放在t所指的数组中:
```c
#include <stdio.h>
#include <string.h>
char* fun(char* s, char* t) {
int len = strlen(s);
int j = 0;
for (int i = 0; i < len; i++) {
if (i % 2 == 0) {
t[j++] = s[i];
}
}
t[j] = '\0';
return t;
}
int main() {
char s[100], t[100];
printf("请输入字符串s:\n");
scanf("%s", s);
printf("去掉下标为奇数的字符后新串为:%s\n", fun(s, t));
return 0;
}
```
在这个函数中,我们首先计算字符串s的长度,然后遍历s中的每个字符,如果该字符的下标是偶数,则将其复制到t中,并递增t的下标j。最后,我们在t的末尾添加一个空字符'\0',表示这是一个字符串的结尾,并返回t的指针。
相关推荐
![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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)