首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
str为一个字符序列。请补充函数fun(),该函数的功能是:查找str中值为x的元素,返回该字符序列中值为x的元素个数,并把这些值为x的元素下标依次保存在数组bb中。例如,在“abcdefahij”中查找‘a’,结果为:2个‘a’,下标依次为 0、6。
str为一个字符序列。请补充函数fun(),该函数的功能是:查找str中值为x的元素,返回该字符序列中值为x的元素个数,并把这些值为x的元素下标依次保存在数组bb中。例如,在“abcdefahij”中查找‘a’,结果为:2个‘a’,下标依次为 0、6。
admin
2010-05-05
34
问题
str为一个字符序列。请补充函数fun(),该函数的功能是:查找str中值为x的元素,返回该字符序列中值为x的元素个数,并把这些值为x的元素下标依次保存在数组bb中。例如,在“abcdefahij”中查找‘a’,结果为:2个‘a’,下标依次为 0、6。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#define N 20
int bb[N];
int fun(char *str,char ch)
{
int i=0, n=0;
char t=ch;
char *p=str;
while(*p)
{
if (【 】)
【 】;
p++;
i++;
}
return【 】;
}
main()
{
char str[N];
char ch;
int i, j,n;
clrscr();
printf("***Input the original string
***\n");
gets(str);
printf("***The Original ***\n");
puts(str);
printf("***Input character ***\n");
scanf("%c",&ch);
n=fun(str,ch);
printf("\nThe numbr of character is:
%d\n", n);
printf{"***The suffix of character
***\n");
for(i=0;i<n;i++)
printf("%d ",bb
);
}
选项
答案
*p==t bb[n++]=I n
解析
第一空:通过指针p的移动来依次访问字符串的各个字符,如果指针p所指的字符等于待查找的字符,即表示找到了满足条件的字符。第二空:将找到的字符在字符数组中的下标值保存在数组bb中。第三空:变量n记录在字符串中找到待查找字符的个数。由main函数的调用可知函数fun()的返回值为n。
转载请注明原文地址:https://jikaoti.com/ti/QSkiFFFM
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
化学与生产、生活息息相关,下列叙述错误的是()。
下列说法错误的是()。
区分国家性质的根据是()。
法院审理一起受贿案时,被告人甲称因侦查人员刑讯不得已承认犯罪事实,并讲述受到刑讯的具体时间。检察机关为证明侦查讯问程序合法,当庭播放了有关讯问的录音录像,并提交了书面说明。关于该录音录像的证据种类,下列哪一选项是正确的?()
国家机构是我国宪法的主要内容之一。下列有关国家机构的说法正确的是()。
能直接证明门捷列夫元素周期表理论正确的是(,)。
有一位百岁老人出生于二十世纪,2015年他的年龄各数字之和正好是他在2012年的年龄的各数字之和的三分之一,问该老人出生的年份各数字之和是多少(出生当年算作0岁)?
一个各位不相同的8位数密码,任意相邻两个数字之和为质数,则最大的8位数各位数字之和为多少?
某种产品每箱中个数相等,将1箱这种产品按照每盒47个的方式重新装盒,最后剩15个;如果将10箱这种产品按照每盒47个重新装盒,问最后剩多少个?()
网络用语从一开始就不是交际语言。文字和语言的性质是不一样的,语言本质上是用声音符号做物质外壳的,文字则是用来记录有声语言的。世界上大多数语言并没有文字,这些语言也就不会有网络用语。文字有记录、保存语言的功能,并能远距离传送,网络主要利用文字来实现即时的远距
随机试题
属于面向过程的语言是()
A、Refinetheirinterviewingtechniques.B、Arrangetheirworkschedules.C、Selectappropriatecourses.D、Writecoverletters.A从“
X线表现肺门增大模糊,肺纹理模糊,肋膈角区见KerleyB线,原因是
A.胸腔内2%苯酚氢钠反复冲洗B.胸腔内注入四环素、红霉素或滑石粉C.胸腔内注入异烟肼、利福平D.胸腔内注入糖皮质激素E.手术治疗支气管胸膜瘘应
按照( )将铸铁分为灰口铸铁、球墨铸铁和可锻铸铁。
根据公司法律制度的规定,下列情形中,构成股东要求司法解散公司的正当理由的是()。(2016年)
论述国际货物运输代理企业在实践中可以提供的服务。
个人简历分析用于人员测评的特点包括()。
联系实际,说说什么样的教师受学生欢迎。
在考生文件夹下JIBEN文件夹中创建名为A2TNBQ的文件夹,并设置属性为隐藏。
最新回复
(
0
)