首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC++2010打开考生文件夹下modi1中的解决方案。此解决方案的项目中包含一个源程序文件modi1.c。在此程序中,函数fun的功能是:从s所指字符串中,找出t所指字符串的个数作为函数值返回。例如,当s所指字符串中的内容为“abcdabfab”,t
使用VC++2010打开考生文件夹下modi1中的解决方案。此解决方案的项目中包含一个源程序文件modi1.c。在此程序中,函数fun的功能是:从s所指字符串中,找出t所指字符串的个数作为函数值返回。例如,当s所指字符串中的内容为“abcdabfab”,t
admin
2021-06-15
37
问题
使用VC++2010打开考生文件夹下modi1中的解决方案。此解决方案的项目中包含一个源程序文件modi1.c。在此程序中,函数fun的功能是:从s所指字符串中,找出t所指字符串的个数作为函数值返回。例如,当s所指字符串中的内容为“abcdabfab”,t所指字符串的内容为“ab”,则函数返回整数3。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
int fun(char*s,char*t)
{
int n;char*p,*r;
n=0;
while(*s)
{
p=s;
r=t;
while(*r)
/*********found*********/
if(*r=*p){r++;p++}
else break;
/*********found*********/
if(r==’\0’)
n++;
s++;
}
return n;
}
void main()
{
char s[100],t[100];int m;
system("CLS");
printf("\nPlease enter string s:");
scanf("%s",s);
printf("\nPlease enter substring t:");
scanf("%s",t);
m=fun(s,t);
printf("\nThe result is:m=%d\n",m);
}
选项
答案
(1)if(*r==*p){r++;p++;} (2)if(*r==’\0’)
解析
从字符串s中找出子串t的方法是:从第1个字符开始,对字符串进行遍历,若s串的当前字符等于t串的第1个字符,两个字符串的指针自动加1,继续比较下一个字符;若比较至字符串t的结尾,则跳出循环;若s串的字符与t串的字符不对应相同,则继续对s串的下一个字符进行处理。
转载请注明原文地址:https://kaotiyun.com/show/8rtp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
若有以下程序typedefstructstu{charname[10],gender;intscore;}STU;voidf(STUa,STUb){b=a;printf("%s,%c,%d,",b.na
以下叙述中错误的是
有以下程序#includemain(){inta=2,b;b=a
以下关于C语言的叙述中正确的是()。
下面程序执行后的输出结果是()。main(){intarray[3][3],*p,i;p=&array[0][0];for(i=p;i<9;i++)p[i]=i+
设循环队列为Q(1:m),初始状态为front=rear=m。现经过一系列的入队与退队运算后,front=rear=1,则该循环队列中的元素个数为()。
数据库设计中反映用户对数据要求的模式是( )。
若i和k都是int类型变量,有以下for语句for(i=0,k=-1;k=1;k++)printf("*****\n");下面关于语句执行情况的叙述中正确的是
以下C语言用户标识符中,不合法的是
设有n个数按从大到小的顺序存放在数组x中,以下能使这n个数在x数组中的顺序变为从小到大的是()。
随机试题
箱涵顶进启动时,当顶力达到()倍结构自重时箱涵未启动,应立即停止顶进。
A.0.5/小时B.小时C.2小时D.3小时E.4小时正常足月儿生后母乳喂养开始时间是
关于手术区的消毒和铺巾,哪项是错误的
题37~40:一多层砖砌体办公楼,其底层平面如图1-10所示。外墙厚370mm,内墙厚240mm,墙均居轴线中。底层层高3.4m,室内外高差300mm,基础埋置较深且有刚性地坪。墙体采用MU10烧结多孔砖、M10混合砂浆砌筑;楼、屋面板采用现浇钢筋混凝土板
下列关于违反银行业监督管理有关法律规定的法律责任的说法中,正确的有()。
“诱因对比效应”研究表明,什么情况下后继强化有效?()
在文件或文件夹“属性”对话框的“常规”选项卡中可设置文件或文件夹的()。
Whatisthewomanplanning?
Whatistheprimarypurposeoftheletter?Toadvisereceiverof______.Whydidthewriterincreaseandcorrecttheirprevio
Againstabackgroundofcontroversialplanstotripleuniversitytuitionfees,studentsshortofmoneymightbeattractedbyan
最新回复
(
0
)