改错题 下列给定程序中,函数FUN的功能是:逐个比较a、b两个字符串对应位置中的字符,把ASCII值大或相等的字符依次存放到c数组中,形成一个新的字符串。例如,若a中的字符串为aBCDeFgH,b中的字符串为:ABcd,则c中的字符串应为:aBcdeFgH。
请改正程序中的错误,使程序能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序: #include <stdio.h>
#include <string.h>
void fun(char *p, char *q, char *c)
{
/********found********/
int k = 1;
/********found********/
while (*p != *q)
{
if (*p < *q)
c[k] = *q;
else
c[k] = *p;
if (*p)
p++;
if (*q)
q++;
k++;
}
}
main()
{
char a[10] = "aBCDeFgH", b[10] = "ABcd", c[80] = {’\0’};
fun(a, b, c);
printf("The string a:");
puts(a);
printf("The string b:");
puts(b);
printf("The result:");
put s(c);
}
第1处:int k=1应改为int k=0;
第2处:while(*p!=*q)应改为while(*p||*q)