首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请补充函数fun(),该函数可以统计一个长度为n的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为:asd ascasdfg asd as asd mlosd,子字符串为asd,则应输出4。 注意:部分源程序给出如下。 请勿改动主函数
请补充函数fun(),该函数可以统计一个长度为n的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为:asd ascasdfg asd as asd mlosd,子字符串为asd,则应输出4。 注意:部分源程序给出如下。 请勿改动主函数
admin
2009-02-15
36
问题
请补充函数fun(),该函数可以统计一个长度为n的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为:asd ascasdfg asd as asd mlosd,子字符串为asd,则应输出4。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填人所编写的若干表达式或语句。
试题程序:
#include < stdio. h >
#include < string. h >
#include < conio. h >
int fun(char * str,char * substr)
{
int n;
char *p,*r;
(1);
while( * str)
{
p = str;
r = substr
while( * r)
if((2))
{
r++;
p++;
{
else
break;
if((3))
n++;
str ++;
}
return n;
}
main( )
{
char str[81],substr[3];
int n;
clrscr ( );
printf("输入主字符串:’);
gets(str);
printf(’输入子字符串:" );
gets( substr );
puts(str);
puts(substr);
n = fun(str,substr);
printf("n=%d\n",n)
}
选项
答案
(1)n=0(2)*r==*p(3)*r==’\0’
解析
填空1:变量n用来记录子字符串在字符串中出现的次数,函数中对变量n进行了类型声明,但并没有进行初始化,所以此处对n初始化为0。填空2:进行比较时,如果子字符串的字符与字符串中的字符相同,则将两个字符串的指针都自加1,继续进行比较,否则跳出循环。填空3:如果此时指针r所指的字符为’\0’,则说明子字符串在字符串中出现了一次,将记录变量n加1。
转载请注明原文地址:https://jikaoti.com/ti/t2i7FFFM
本试题收录于:
软件设计师下午应用技术考试题库软考中级分类
0
软件设计师下午应用技术考试
软考中级
相关试题推荐
某个应用中,需要对输入数据进行排序,输入数据序列基本有序(如输入为1,2,5,3,4,6,8,7)。在这种情况下,采用(40)排序算法最好,时间复杂度为(41)。(41)
模块A的功能为:从数据库中读出产品信息,修改后存回数据库,然后将修改记录写到维护文件中。该模块内聚类型为(38)内聚。以下关于该类内聚的叙述中,正确的是(39)。(39)
某软件项目的活动图如下图所示,其中顶点表示项目里程碑,连接顶点的边表示包含的活动,边上的数字表示活动的持续时间(天),则完成该项目的最少时间为(33)天。活动BC和BF分别最多可以晚开始(34)天而不会影响整个项目的进度。(33)
一个程序的控制流图中有6个节点,10条边,在测试用例数最少的情况下,确保程序中每个可执行语句至少执行一次所需要的测试用例数的上限是______。
某系统中仅有5个并发进程竞争某类资源一且都需要该类资源3个,那么该类资源至少有()个,才能保证系统不会发生死锁。
假定X为整数类型变量,X>=1并且X<=10,如果用边界值分析法,X在测试中应该取(48)值。
软件测试的基本方法包括白盒测试和黑盒测试方法,以下关于二者之间关联的叙述,错误的是(61)。
系统交付后,修改原来打印时总是遗漏最后一行记录的问题,该行为属于______维护。
运行Web浏览器的计算机与网页所在的计算机要建立(66)连接,采用(67)协议传输网页文件。
阅读以下说明,回答问题1至问题4。【说明】网络工程师经常会面对服务器性能不足的问题,尤其是网络系统中的核心资源服务器,其数据流量和计算强度之大,使得单一计算机无法承担。可以部署多台Linux服务器组成服务器集群,采用负载均衡技术提供服务。
随机试题
奥地利的马赫提出“物是感觉的复合”。这是一种()。
TheNationalWeatherServiceatRyanAirportbroughtoutthefollowingforecast(预报).SaturdaynightforSatonpRougeandvicini
纤溶酶的主要作用是水解
男,62岁,2个月前就诊某医院,确诊为特发性血小板减少性紫癜,予以泼尼松每天60mg口服,住院2周后病情好转带药出院。2天前,泼尼松服完,未再服用。今再次发现全身皮肤瘀点、瘀斑,就诊我院。血象检查为红细胞5.1×1012/L、白细胞5.6×109/L、血小
融资信用保证结构设计及评价应考虑的因素不包括()。
声压级的单位是(A)
以提升教育对象的智慧水平为目标的教育即()。
防火墙通常分为内网、外网和DMZ三个区域,按照受保护程度,从高到低正确的排列次序为__________________。
Theteachingmethodshouldbevariedatdifferentstagesoflearning______achievingbetterresults.
Amazon,whichgotitsstartsellingbooksonline,announcedthisyearthat,forthefirsttime,itsdigitalbookshadoutsold
最新回复
(
0
)