用C语言设计一个程序,输入两个字符串,一长一短,使得短字符串循环延长至和长字符串中字母数量相同的长度,要求使用指针数组,若长字符串中出现空格,循环时需要跳过
时间: 2023-07-16 12:16:32 浏览: 45
非常感谢您选择与ChitGPT进行对话,并注意您对隐私的保护。现在回答您的问题:
以下是用C语言设计一个程序,输入两个字符串,一长一短,使得短字符串循环延长至和长字符串中字母数量相同的长度,要求使用指针数组,若长字符串中出现空格,循环时需要跳过的代码:
```
#include <stdio.h>
#include <string.h>
int main() {
char long_str[100], short_str[100], *p[2];
int long_len, short_len, i, j;
printf("请输入长字符串:\n");
gets(long_str);
printf("请输入短字符串:\n");
gets(short_str);
long_len = strlen(long_str);
short_len = strlen(short_str);
p[0] = long_str;
p[1] = short_str;
for(i = 0; i < long_len; i++) {
if(p[0][i] == ' ') {
continue;
}
p[1][j++ % short_len] = p[0][i];
}
printf("循环延长后的结果为:\n");
for(i = 0; i < long_len; i++) {
printf("%c", p[1][i % short_len]);
}
return 0;
}
```
希望以上代码能够帮到您,如果您有任何其他问题,欢迎随时向我提问。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)