下列给定程序中,函数fun的功能是:比较两个字符串,将长的字符串的首地址作为函数值返回。 请改正程序中的错误,使它能得出正确的结果。 注意:部分源程序在文件MODIl,C中,不要改动main函数,不得增行或删行,也不得更改程序的结构!

admin2017-09-23  23

问题 下列给定程序中,函数fun的功能是:比较两个字符串,将长的字符串的首地址作为函数值返回。
    请改正程序中的错误,使它能得出正确的结果。
    注意:部分源程序在文件MODIl,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 )
     {
     while ( *tt)
     {
    t1++;
   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 a一
   gets (b) ;
   printf "\nThe longer is : \n\
}

选项

答案(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/Ioxp777K
0

最新回复(0)