首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请补充函数proc(),该函数可以统计一个长度为n的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为:asd ascasdfg asd as as mlosd,子字符串为asd,则应输出3。 注意:部分源程序给出如下。 请勿改动函
请补充函数proc(),该函数可以统计一个长度为n的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为:asd ascasdfg asd as as mlosd,子字符串为asd,则应输出3。 注意:部分源程序给出如下。 请勿改动函
admin
2013-03-25
32
问题
请补充函数proc(),该函数可以统计一个长度为n的字符串在另一个字符串中出现的次数。例如,假定输入的字符串为:asd ascasdfg asd as as mlosd,子字符串为asd,则应输出3。
注意:部分源程序给出如下。
请勿改动函数main()和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
试题程序:
#include
#inelude
#include
#include
int proc(char * str.char * sub)
{
int n;
char * p,* r;
【1】;
while(* str)
{
p=str;
r=sub;
while(* r)
if(【2】)
{
r++;
p++;
}
else
break;
if(【3】 )
n++;
str++;
}
return n;
}
void main()
{
char str[81],sub[3];
int n;
system("CLS");
printf("输入主字符串:");
gets(str);
printf("输入子字符串:");
gets(sub);
puts(str);
puts(sub);
n=proe(str,sub);
printf("n:%d\n",n);
}
选项
答案
【1】n=0【2】*r==*p【3】*r==’\0’
解析
由函数proc可知,变量n为字符串str中子字符串的个数,其初始值为0,因此,【1】处填“n=0”。字符指针变量p和r分别指向字符串和子字符串,要对其指向的每一个字符进行比较,因此,【2】处填“*r==*p”。每比较完一次。要检查指针r是否指向子字符串的结束位置,如果是说明字符串中包含一个子字符串,因此,【3】处填“*r==’\0’”。
转载请注明原文地址:https://kaotiyun.com/show/8XJp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
有以下结构体说明和变量的定义,且指针p指向变量a,指针q指向变量b。则不能把结点b连接到结点a之后的语句是structnode{chardata;structnode*next;}a,b,*p=&a,*q=&b
若有以下定义和语句,则对a数组元素地址的正确引用为inta[2][3],(*p)[3];p=a;
若有如下程序:main(){intx=5,y,*t;t=&x;y=++(*t);printf("%d,%d",x,y);}则程序执行后的x值为【】,y的值为【】。
以下程序的功能是:输出x、y、z三个变量中的最大值,请填空。main(){intx,y,z,u;printf("Enterx,y,x;");scanf("%d%d%d",&x,&y,&z);if(【】)u=x
以下程序段用于构成一个简单的单向链表。请填空。struetSTRU{intx,y;floatrate;【】p;}a,b;a.x=0;a.y=0;a.rate=0;a.p=
数据模型按不同应用层次分成3种类型,它们是概念数据模型、【】和物理数据模型。
fprintf函数的一般调用方式是()
以下程序段给数组所有的元素输入数据,请选择正确答案填入。()#inelude<stdio.h>main(){inta[10],i=0;while(i<10)scanf("%d",______);
在程序设计阶段应该采取【】和逐步求精的方法,把一个模块的功能逐步分解,细化为一系列具体的步骤,进而用某种程序设计语言写成程序。
随机试题
免疫复合物型变态反应属于Ⅲ型超敏反应。
HELLP综合征是妊娠期高血压的严重并发症,其特点为下列哪项
决定肾结核的治疗方法,除全身情况外主要依靠
我国刑事诉讼法所调整的对象有:()
预应力钢筋中的预加力为( )。假定预应力钢筋中的预加力Ny0为720.6kN,开裂截面混凝土的名义拉应力为( )。
在我国,()具有最高法律效力。
根据对组织的态度的不同可以将公众分为顺意公众、逆意公众和独立公众。顺意公众指的是对组织的政策和行为持赞赏和支持态度的公众;逆意公众指的是对组织的政策和行为持否定或反对态度的公众;独立公众指的是对组织的政策和行为持中间态度的公众。根据上述定义,以下属于顺意
下列属于二次文献的是()。
在关系模型中,每一个二维表称为一个
WhichofthefollowingitalicizedwordsdoesNOTindicatewillingness?
最新回复
(
0
)