填空题 C语言
题号 #2254540

请补充函数proc(char*str),该函数的功能是把字符串中的内容逆置。
例如,字符串中原有的字符串为abcdefg,则调用该函数后,串中的内容变为gfedcba。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdlib.h>
#include t<string.h>
#include<conio.h>
#include<stdio.h>
#define M 81
void proc(char*str)

 

      【2】 ;
【3】 ;
}
}
void main()
{
char str[M];
system("CLS"):
printf("Enter a string:");
gets(str);
printf("The original string is:");
puts(str);
proc(str);
printf("\n");
printf("The string after modified:");
puts(str);
}

进入在线模考

参考答案

暂无

答案解析

【1】i<n/2【2】*(str+i)=*(str+n-1-i) 【3】* (str+n-1-i)=t
【解析】要将字符串中的内容逆置.可以通过将字符串中的第一个字符和最后一个字符互换,第二个和倒数第二个互换,直到字符串str最中间的字符为止,因此,【1】处填“i <n/2”。for循环体中的语句功能为将第i个字符与第(n- 1-i)个字符互换,因此,【2】处填“*(str+i)=*(str+n-1 -i)”;【3】处填“*(str+n-1-i)=t”。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考