首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
阅读下列程序,当运行函数时,输入asd af aa z67,则输出为 #include #include #include int fun (char *str) { int i,j=0; for(i=0;str[i]!=′ \0′;
阅读下列程序,当运行函数时,输入asd af aa z67,则输出为 #include #include #include int fun (char *str) { int i,j=0; for(i=0;str[i]!=′ \0′;
admin
2010-12-10
20
问题
阅读下列程序,当运行函数时,输入asd af aa z67,则输出为
#include
#include
#include
int fun (char *str)
{ int i,j=0;
for(i=0;str
!=′ \0′;i++)
if(str
!=′ ′)str[j++]=str
;
str[j]= ′\0′;
}
main()
{
char str[81];
int n;
printf("Input a string : ");
gets(str);
puts(str);
fun(str);
printf("%s\n",str);
}
选项
A、asdafaaz67
B、asd af aa z67
C、asd
D、z67
答案
A
解析
本题题意要求删除所有空格,即除了空格以外的其他所有字符都要留下。由于C语言中没有直接删除字符的操作,所以我们对于删除字符的操作都是采用"留下"字符的算法,以前的题目亦是如此。用str
从串头到串尾逐一走动,每走到一个字符都判断其是否为空格,若不是空格(注意在if()的单引号之间有一个空格),则将其保存str[j]中。注意j的下标变化、初值及最后加串结束符’\0’。
转载请注明原文地址:https://kaotiyun.com/show/asPp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
实现字符的UniCode编码方式一-~ANSI编码方式相转换的函数是()。
以下关于文件的叙述中,错误的是
窗体上有1个名称为List1的列表框,其中有若干列表项,并有下面程序代码:PrivateSubList1_DblClick()ExchangeList1,List1.ListIndexEndSubPriva
要使两个单选按钮属于同一个框架,下面三种操作方法中正确的是()。①先画一个框架,再在框架中画两个单选按钮②先画一个框架,再在框架外画两个单选按钮,然后把单选按钮拖到框架中③先画两个单选按钮,再画框架将单选按钮框起来
编写如下程序:PrivateSubForm_Click() Print"Welcome!"EndSubPrivateSubForm_MouseDown(ButtonAsInteger,ShiftAsInteger,XAs
编写如下程序:PrivateSubCommand1_Click()DimnumAsIntegerDimkAsInteger,nAsIntegernum=InputBox("请输入一个正整数:")k
下列关于菜单项的描述中,错误的是
以下打开VisualBasic菜单编辑器的操作中,错误的是( )。
某人编写了下面的程序,希望能把Text1文本框中的内容写到Temp.txt文件中PrivateSubCommand1_Click()Open"Temp.txt"ForOutputAs#2Print"Text1"Close#2EndSub
窗体上有一个名称为Option1的单选按钮数组,程序运行时,当单击某个单选按钮时,会调用下面的事件过程:PrivateSubOption1_Click(IndexAsInteger)EndSub下面关于此过程的参数I
随机试题
A、张口受限B、复视C、耳鼻出血D、颅面分离E、咬牙合错乱颅底骨折常伴有
期间费用包括()。
下列选项中,企业可以考虑实行前向一体化战略的是()。
2000年《中国居民膳食营养素参考摄入量》推荐学龄前儿童维生素A的可耐受最高剂量为()μg/日。
沙滩排球_______年起源于_______,_______年开始传入欧洲,_______年正式成为奥运会正式比赛项目。
警衔是区分人民警察()、表明人民警察身份的称号、标志和国家给予人民警察的荣誉。
市场经济是以计划作为资源配置的基础性手段的经济运行模式。()
完善民间投资的配套设施和实施细则,增加了民资的投资选择余地,对于缺乏投资渠道的民间资本可以起到_______作用,避免民间资本集中于住房、股票等_______的投资领域,也可激活民间的创业热情,弥补政府资金的不足。填入画横线部分最恰当的一项是:
下列关于外部网关协议BGP的描述中,错误的是()。
下列关于二叉树的叙述中,正确的是( )。
最新回复
(
0
)