填空题
下列给定程序中,函数proc()的功能是逐个比较str1,str2两个字符串对应位置中的字符,把比ASCII值大或相等的字符依次存放到str数组中,形成一个新的字符串。
例如,str1中的字符串为fshADfg,str2中的字符串为sdAEdi,则str中的字符串应为sshEdig。
请修改程序中的错误,使它能得到正确结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
#include<string.h>
void proc(char*p,char*q,char*c)
{ int k=0;
while(*p||*q)
//****found****
{if(*p>=*q)
c[k]=*q;
else c[k]=*p;
if(*p)p++;
if(*q)q++;
//****found****
k++
}
}
void main()
{char str1[10]="fshADfg",str2[10]="sdAEdi",
str[80]={"/0"};
proc(str1,str2,str);
printf("The string str1:");puts(str1);
printf("The string str2:");puts(str2);
printf("The result:");puts(str);
}