#include <stdio.h> void fun(char *t,char *s){ while(*t!=0)t++; while((*t++=*s++)!=0); main() [char ss[10]=“acc”,aa[10]="bbxxyy"; fun(ss,aa); printf("%s,%s\n",ss,aa); 程序的运行
时间: 2024-04-01 21:31:59 浏览: 16
结果会输出:acc,bbxxyy。这是因为程序中的fun函数实现了将字符串s复制到字符串t的功能,即将字符串s中的内容复制到字符串t的末尾,并在末尾加上字符串结束符'\0'。在主函数中,先定义了两个字符串数组ss和aa,分别初始化为"acc"和"bbxxyy"。然后调用fun函数,将aa的内容复制到了ss的末尾,并且在ss的末尾添加了字符串结束符。最后,主函数中输出了ss和aa的内容,因此输出结果为"acc,bbxxyy"。
相关问题
#include <string.h> #include <stdio.h> #include <ctype.h> void fun(char *p) { int i, t; char c[80]; /********found********/ For (i=0, t=0; p[i]; i++) if (!isspace(*(p+i))) c[t++] = p[i]; /********found********/ c[t] = "\0"; strcpy(p, c); } void main() { char c, s[80]; int i = 0; c = getchar(); while (c != '#') { s[i] = c; i++; c = getchar(); } s[i] = '\0'; fun(s); puts(s); }
这段代码的功能是将输入的字符串中的空格删除,并输出删除后的字符串。但是代码有两处错误:
1. 第一个错误是在第 10 行,`For` 应该改为小写字母 `for`。
2. 第二个错误是在第 13 行,字符串结束符应为 `'\0'` 而不是 `"\0"`。
正确的代码应该是:
```c
#include <string.h>
#include <stdio.h>
#include <ctype.h>
void fun(char *p) {
int i, t;
char c[80];
for (i = 0, t = 0; p[i]; i++) {
if (!isspace(*(p+i))) {
c[t++] = p[i];
}
}
c[t] = '\0';
strcpy(p, c);
}
int main() {
char c, s[80];
int i = 0;
c = getchar();
while (c != '#') {
s[i] = c;
i++;
c = getchar();
}
s[i] = '\0';
fun(s);
puts(s);
return 0;
}
```
请使用while函数将fun函数的内容补充完整,编写出一个C语言程序,对字符串,除首、尾字符外,将其字符按ASCII编码数值降序排列的操作:#include<stdio.h> #include<ctype.h> #include<string.h> #include<conio.h> void wwjt(); void fun(char *a,int len) { int i,j; char t; } main(){ char s[100]; int l; printf("输入字符串:"); gets(s); l=strlen(s); fun(s,l); printf("\n%s\n",s); wwjt(); }
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<conio.h>
void wwjt();
void fun(char *a, int len) {
int i, j;
char t;
i = 1;
j = len - 2; //除去首尾字符后的最后一个字符的下标
while (i < j) {
while (i < j && a[i] > a[j]) {
t = a[i];
a[i] = a[j];
a[j] = t;
i++;
j--;
}
i++;
j--;
}
}
int main() {
char s[100];
int l;
printf("输入字符串:");
gets(s);
l = strlen(s);
fun(s, l);
printf("\n%s\n", s);
wwjt();
return 0;
}
void wwjt() {
printf("我爱计算机网络课程设计!\n");
}
相关推荐
![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)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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://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)