使用VC++2010打开考生文件夹下modi1中的解决方案。此解决方案的项目中包含一个源程序文件modi1.c。在此程序中,函数fun的功能是:比较两个字符串,将长的字符串的首地址作为函数值返回。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程

admin2020-01-10  23

问题 使用VC++2010打开考生文件夹下modi1中的解决方案。此解决方案的项目中包含一个源程序文件modi1.c。在此程序中,函数fun的功能是:比较两个字符串,将长的字符串的首地址作为函数值返回。
请改正程序中的错误,使它能得出正确的结果。
注意:部分源程序在文件MODI1.C中,不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<conio.h>
#include<stdio.h>
/*********found*********/
double fun(char*s,char*t)
{
int s1=0,t1=0;
char*ss,*tt,
ss=s;
tt=t;
while(*ss)
{
s1++;
/*********found*********/
(*ss)++;
}
while(*tt)
{
t1++;
/*********found*********/
(*tt)++;
}
if(t1>s1)
return t;
else
return s;
}
void main()
{
char a[80],b[80];
printf("\nEnter a string:");
gets(a);
printf("\nEnter a string again:");
gets(b);
printf("\nThe longer is:\n\n%s\n",fun(a,b));
}

选项

答案(1)char*fun(char*s,char*t) (2)ss++; (3)tt++;

解析 (1)在主函数的输出语句中,函数fun是以字符
串格式输出的,所以定义函数时应为
char*fun(char*s,char*t)。
(2)和(3)这里是地址加1,而不是内容加1,所以改为ss++和tt++。
转载请注明原文地址:https://kaotiyun.com/show/BFCp777K
0

最新回复(0)