首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
编写函数fun,其功能是:求ss所指字符串中指定字符的个数,并返回此值。 例如,若输入字符串“123412132”,输入字符为“1”,则输出3。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fu
编写函数fun,其功能是:求ss所指字符串中指定字符的个数,并返回此值。 例如,若输入字符串“123412132”,输入字符为“1”,则输出3。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fu
admin
2019-06-27
2
问题
编写函数fun,其功能是:求ss所指字符串中指定字符的个数,并返回此值。
例如,若输入字符串“123412132”,输入字符为“1”,则输出3。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<Stdio.h>
#define M 81
int fun(char*SS,char c)
{
}
voidmain()
{
char a[M],ch;
system(“CLS”);
printf(“\nPlease enter a
string:”);
gets(a);
printf (“\nPlease enter a char:”);
ch=getchar();
printf(“\nThe number of the char
is:%d\n”,fun(a,ch));
}
选项
答案
int fun(char*ss,char c) { int i=0; for(;*ss!=‘\0’; ss++) if(*ss==c) i++; /*求出8s所指字符串中指定字符的个数*/ return i; }
解析
从字符串中查找指定字符,需要使用循环判断结构,循环语句用来遍历字符串,循环条件为字符串没有结束,即当前字符不是‘\0’,判断语句用来判断当前字符是否为指定宁符。最后返回指定字符的个数。
转载请注明原文地址:https://kaotiyun.com/show/NaID777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
近年来,随着微博、微信等网络社交媒体的迅速发展,有关食品的谣言甚嚣尘上,给人们的日常生活带来很大困扰。在日前召开的中国食品辟谣论坛上,中国食品谣言智能预警处理平台正式上线,被寄予了破解食品谣言满天飞现状的厚望。健全和完善食品安全举报的平台和机制,把举报机制
下面句子中,语法结构与其他三句不同的是()。
6.微笑是人类表达感情的有效途径。神奇的是,如果对方是假笑,你回应以同样的微笑,你的前额脑区底部并不会变活跃,于是就会意识到对方的微笑有些不对劲,并且很快会断定,这人是在假笑。这说明,________。填入画横线部分最恰当的一句是()。
下列选项中的现象所蕴含的物理原理相同的是()。
在现代社会,基础教育的普及、义务教育年限的延长、职业教育的大力发展、高等教育的大众化趋势都是由生产力发展需要决定的。这表明
阅读下列材料,运用有关教育理论加以分析。材料一:在中国教育学会家庭教育专业委员会的一项面向小学四到六年级学生的调研中,到了六年级的学生,自己洗内衣裤的孩子比例不超过一半,经常参加家务劳动的比例仅为21.6%,有17.2%的孩子做作业仍需要家长陪。
设曲线L的参数方程为x=φ(t)=t—sint,y=ψ(t)=1一cost(0≤t≤2π).(Ⅰ)求证:由L的参数方程确定连续函数y=y(x),并求它的定义域;(Ⅱ)求曲线L与x轴所围图形绕Oy轴旋转一周所成旋转体的体积V;(Ⅲ)设曲线L与x轴围
设D是由抛物线y=x2与曲线围成的平面区域,函数f(x,y)在D上连续,则=()
某商品经营管理系统使用SQLServer数据库。在数据库中存在销售单据表,建表语句为:CREATETABLE销售单据表(销售单据编号char(20),付款总金额money,销售日期datetime,销售人员
请根据下图所示网络结构回答下列问题。如果需要IP地址为59.67.151.128的主机使用第三方软件监控路由器RG的运行状态,请写出路由器RG必须支持的协议名称_________。
随机试题
女性生殖道感染可以通过各种不同的方式导致女性不孕,不同的病原生物可以通过影响子宫内膜、输卵管、精子数量和活力等造成女性不孕。生殖道支原体感染对女性生育的影响,以下哪项描述不正确
某一工程从现场取SBS改性沥青样品进行试验,请回答下列问题。以下关于该样品离析试验,说法正确的是()。
某月内,X商品的替代品的价格上升和互补品的价格上升,分别引起X商品的需求变动量为50单位和80单位,则在它们共同作用下该月X商品需求数量()。
“依恋”理论认为儿童的欺负行为是()。
公安机关的治安行政管理是国家行政管理的重要内容,是在()的领导下实行的。
《“十二五”规划的建议》提出,“十二五”期间置于我国区域发展总体战略优先位置的是()。
以下洗剂用品,最为环保的是()
【B1】【B20】
SaintPatrick’sDay,whichmemorizesSt.Patrick,patrongodofIreland,ison
Weshouldmakeaclear______between’competent’and’proficient’forthepurposesofourdiscussion.
最新回复
(
0
)