编写一个甬数,其功能是:从传人的num个字符中找出最长的一个字符串,并通过形参指针max传回该串地址(用****作为结束输入的标识)。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的

admin2020-01-10  45

问题 编写一个甬数,其功能是:从传人的num个字符中找出最长的一个字符串,并通过形参指针max传回该串地址(用****作为结束输入的标识)。
    注意:部分源程序在文件PROG1.C中。
    请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
    试题程序:
1  #include<conio.h>
2   #include<stdio.h>
3  #include<string.h>
4  #include<stdlib.h>
5  char*fun(char(*a)[81],int  num,char*max)
6  {
7
8  }
9  void main()
10  {
11    FILE*wf;
12  char ss[10][81],*ps=NULL;
13    char s[3][81]={’’abcd’’, ’’deg’’,’’diegns’’},*p=NULL;
14    int i=0,n;
15    system(’’CLS’’);
16  printf(’’输入若干个字符串:’’);
17  gets(ss);
18   puts(ss);
19  while(!strcmp(ss,’’****’’)==0)/*用4个星号作为结束输入的标志*/
20  {
21    i++;
22    gets(ss);
23
24   puts(ss);
25    }
26    n=i:
27    ps=fun(ss,n,ps);
28  printf(’’\nmax=%s\n’’,ps);
29    /*****************/
30    wf=fopen(’’out.dat’’,’’w’’);
31    p=fun(s,3,p);
32    fprintf(wf,’’%s’’,p);
33    fclose(wf);
34    /*****************/
35  }

选项

答案1 char*fun(char(*a)[81],int num,char*max) 2 { 3 int i=0; 4 max=a[0]; 5 for(i=0 ; i
解析 解答本题之前,首先应该明白ss是一个指向一维数组的指针变量,max是指向指针的变量,所以引用变量时要注意加上*。本程序使用循环语句遍历字符串数组,使用条件语句判断该字符串是否最长。
转载请注明原文地址:https://jikaoti.com/ti/vNG0FFFM
0

相关试题推荐
随机试题
最新回复(0)