下面程序的功能是在字符串每个字符间插入一个空格。 程序的运行结果如下: Input a string:Howareyou↙ Insert results:H o w a r e y o u 按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。 #include <stdio.h> #include <string.h> #define N 100 void Insert(char s[]); int main() { char str[N]; printf("Input a string:"); gets(str); Insert(str); printf("Insert results:%s\n", str); return 0; } void Insert(char s[]) { char t[N]; int i, j; ____________; for (i=0, j=0; ____________; i++, j++) { ________; j++; ________; } s[j] = '\0';/* 在字符串s的末尾添加字符串结束标志 */ }
A、第19行:strcpy(t, s) 第20行:t[i]!='\0' 第22行:s[j] = t[i] 第24行:s[j] = ' '
B、第19行:t=s; 第20行:t[i]!='\0' 第22行:s[i] = t[j] 第24行:s[j] = ' '
C、第19行:strcpy(t, s) 第20行:t[i]='\0' 第22行:t[j] = s[i] 第24行:s[j] = '\0 '
D、第19行:strcpy(s, t) 第20行:t[i]=='\0' 第22行:s[j] = t[i] 第24行:s[j] = '0 '
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <string.h>
include <stdio.h>
define N 80
void insert(char *aa)
{
int i,j,n; char ch;
n=strlen(aa);
for(i=1;i<n;i++)
{
ch=aa[i];
j=i-1;
/*************found*************/
while((j>=0)||(ch>aa[j]))
{
aa[j+1]=aa[j];
j--;
}
/*************found*************/
aa[j]=ch;
}
}
main()
{
char a[N]="JRTYDFKLIOPQWEGHMNBVCUASXZ";
int i;
printf("The original string: %S\n",a);
insert(a);
printf("The string after sorting:%S\n\n",a);
}
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!