#include<conio.h>#include<stdio.h>#include<string.h> void fun(char s[],char t[]) I int i,k; k=strlen(s); /**********ERROR**********/ for(i=5;i<k;i++) t[i]=s[i]; for(i=5;i<k;i++) /**********ERROR****美*美*美*/ t[k+i]=s[k-i]; /**********ERROR**********/ t[k]='\0'; main(){ char s[150],t[156]; printf("\nPlease enter string s:");scanf("%s",s);/**********ERROR**********/ fun(s,t); printf("The result is:%s\n",t);
时间: 2023-07-23 08:28:56 浏览: 52
这段代码存在三处错误。第一处错误是函数fun没有正确的定义,应该为void fun(char s[], char t[])。第二处错误是在第7行的for循环中,应该使用i作为下标,而不是5。第三处错误是在第8行的for循环中,应该使用k-i-1作为下标,而不是k-i。改正后的代码如下:
```
#include <stdio.h>
#include <string.h>
void fun(char s[], char t[]) {
int i, k;
k = strlen(s);
for (i = 0; i < k; i++) {
if (i < 5) {
t[i] = s[i];
} else {
t[i] = s[k - i - 1];
}
}
t[k] = '\0';
}
int main() {
char s[150], t[156];
printf("\nPlease enter string s:");
scanf("%s", s);
fun(s, t);
printf("The result is:%s\n", t);
return 0;
}
```
相关问题
完成以下C语言代码功能:将主函数中输入的字符串反序存放。#include<stdio. h> #include<conio. h> #include(string. h> #define N 50 void fun(char *str, int n)
我可以提供一个示例代码:#include <stdio.h>
#include <string.h>int main ()
{
char str[100], temp;
int i, j; printf("输入一个字符串: ");
gets(str); j = strlen(str) - 1; for (i = 0; i < j; i++, j--)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
} printf("反序后的字符串: %s", str); 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");
}
相关推荐
![application/x-gzip](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)
![](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)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)