首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
编写一个甬数,其功能是:从传人的num个字符中找出最长的一个字符串,并通过形参指针max传回该串地址(用****作为结束输入的标识)。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的
编写一个甬数,其功能是:从传人的num个字符中找出最长的一个字符串,并通过形参指针max传回该串地址(用****作为结束输入的标识)。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的
admin
2020-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
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
下列选项中,能正确定义数组的语句是
若有以下程序#includemain()(inta=1,b=2,c=3,d=4;if((a=2)&&(b=1))c=2;if((c==3)||(d=-1))a=5;
下列给定程序中,函数fun的功能是:将n个无序整数从小到大排序。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<conio.h>#include<stdio.
给定程序中,函数fun的功能是:统计形参s所指的字符串中数字字符出现的次数,并存放在形参t所指的变量中,最后在主函数中输出。例如,若形参s所指的字符串为“abcdef35adgh3kjsdf7”,则输出结果为4。请在程序的下画线处填入正确内容并将下画线
给定程序中,函数fun的功能是:在3×4的矩阵中找出在行上最大、在列上最小的那个元素,若没有符合条件的元素则输出相应信息。例如,有下列矩阵:12134781063597程序
下列给定程序中,函数fun的功能是:将形参s所指字符串中下标为奇数的字符按ASCII码大小递增排序,并将排序后下标为奇数的字符取出,存入形参P所指字符数组中,形成一个新串。例如,形参s所指的字符为“baawrskjghzlicda”,执行后P所指字符数组
若变量已正确定义,以下选项中非法的表达式是
编写函数fun,它的功能是:利用以下所示的简单迭代方法求方程:cos(x)-x=0的一个实根。xn+1=cos(xn)迭代步骤如下:(1)取x1初值为0.0;(2)x0=x1,把x1的值赋给x0;(3)x1=cos(x0)
一棵二叉树中共有70个叶子节点与80个度为1的节点,则该二叉树中的总节点数为()。
随机试题
女性,30岁,背部肿块,红、肿、疼痛3天,寒战、发热39℃,查体:背部肿物3cm×5cm,触之有波动感。当病灶做局部引流和全身应用抗生素后,仍有寒战、高热。最合适的治疗措施是
关于抗菌药物的配伍禁忌A、青霉素B、氨基糖苷类C、头孢菌素类D、红霉素E、两性霉素B与头孢菌素联用可致肾毒性增强的是
术后急性胃扩张的处理,下列措施最重要的是
案情:李某和王某共同抢劫致人死亡,被某中院一审,一审后李某被判死刑,缓期两年执行,王某被判有期徒刑十年。问题:本案如果李某上诉了,王某没有上诉,问二审法院该如何处理?
位于两个安全出口之间的中学普通教室,面积不大于()时可设一个疏散门。
下列相关服务中,属于理财顾问服务的有()。
商店里的货品有标价,如一支钢笔标价为6元。在这里,货币执行的是()的职能。
典型常常是文学至高的美学追求。()
A和B订立的合同中内容约定不明确,按照合同有关条款内容不能确定,且他们又不能通过协商达成协议时,下列解决办法不符合法律规定的是()。
反对中小学生阅读《三国演义》,是一种杞人忧天的行为。这种家长式的焦虑非常可笑,就像劝阻孩子不要碰一块蛋糕一样,没有别的办法,只好说那块蛋糕里面长满了毒素。而事实证明,已经有无数人在吃过那块“蛋糕”之后是安然无恙的,再用夸张的词汇去形容它的不堪就是说谎了。这
最新回复
(
0
)