测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A36775. 给定程序函数fun的功能是:比较两个字符串,将长的那个字符串的首地址作为函数值返回。请改正程序中的错误,使它能得出正确的结果。不要改动main函数,不得增行或删行,也不得更改程序的结构!#include <conio.h>#include <stdio.h>/**********found**********/char fun(char *s, char *t){ int s1=0, t1=0;…

填空题 困难

题目描述

给定程序函数fun的功能是:比较两个字符串,将长的那个字符串的首地址作为函数值返回。


请改正程序中的错误,使它能得出正确的结果。

不要改动main函数,不得增行或删行,也不得更改程序的结构!

#include <conio.h>

#include <stdio.h>

/**********found**********/

char 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++;

        tt++;

    }

    if (t1>s1)

    {

        return t;

    }

    else 

    {

        return s;

    }

}

main()

{

    char a[80],b[80];

    printf("\nEnter a string:");

    gets(a);

    printf("\nEnter a string again:");

    gets(b);

    printf("\n\nThe longer is:\n\n%s\n",fun(a,b));

    system("pause");

}

参考答案

<p>1. 正确答案: char*fun(char *s,char *t)</p><p>2. 正确答案: ss++;</p>
上一题 下一题