首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下列给定程序中函数fun的功能是:将s所指字符串中出现的与t1所指字符串相同的了串全部替换为t2所指字符串,所形成的新串放在w所指的数组中。要求t1和t2所指字符串的长度相同。 例如,当s所指字符串中的内容为“abcdabfab”,t1所指子串中的
下列给定程序中函数fun的功能是:将s所指字符串中出现的与t1所指字符串相同的了串全部替换为t2所指字符串,所形成的新串放在w所指的数组中。要求t1和t2所指字符串的长度相同。 例如,当s所指字符串中的内容为“abcdabfab”,t1所指子串中的
admin
2020-11-27
20
问题
下列给定程序中函数fun的功能是:将s所指字符串中出现的与t1所指字符串相同的了串全部替换为t2所指字符串,所形成的新串放在w所指的数组中。要求t1和t2所指字符串的长度相同。
例如,当s所指字符串中的内容为“abcdabfab”,t1所指子串中的内容为“ab”,t2所指子串中的内容为“99”时,在W所指的数组中的内容应为“99cd99t99”。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#inclucle<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void fun(char*s,char*t1,char*t2,
char*w)
{
char*P,*r,*a;
strcpy(w,s);
while(*w)
{
P=w;r=t1;
/**********found***********/
while(r)
if(*r==*P){r++,P++,)
else break,
if(*r==‘\0’)
{
a=w;r=t2;
while(*r)
/**********found***********/
{*a=*r;a++;r++}
w+=strlen(t2);
}
else w++:
}
}
void main()
{
char s[100],t1[100],t2[100],
w[100];
system(“CLS”),
printf(“\nPlease enter
string S:”);
scanf(“%s”,s),
printf (“\nPlease enter substring t1:”);
scanf(“%s”,t1),
printf (“\nPlease enter
substring t2:”);
scanf(“%s”,t2);
if(strlen(t1)==strlen(t2))
{
fun(s,t1,t2,w);
printf(“\nThe result is:%s
\n”,w),
}
else
printf(“Error:strlen(t2)\n”),
}
选项
答案
(1)while(*r) (2)*a=*r;a++;r++;
解析
while(r)和r++都是简单的逻辑和语法错误,C语言中语句必须以分号“;”结尾。只要掌握了C语言的基础知识,发现这样的错误是很容易的。
转载请注明原文地址:https://kaotiyun.com/show/pZ3p777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
有以下程序#includestructord{intx,y;}dt[2]={1,2,3,4};main(){structord*p=dt;printf("%d,",++(p->x));printf("%d\n",++(
以下叙述中正确的是
若以下选项中的变量a,b,y均已正确定义并赋值,则语法正确的switch语句是
若有以下程序#includemain(){inta=6,b=0,c=0;for(;a;){b+=a;a-=++c;}printf("%d,%d,%d\n",a,b,c);}则程序的输出结果是()。
将E-R图转换为关系模式时,实体和联系都可以表示为
若有以下程序段doublex=5.16894;printf("%f\n",(int)(x*1000+0.5)/(double)1000);则程序段的输出结果是
有以下程序#include<stdio.h>main(){FILE*fp;charstr[10];fp=fopen("myfile.dat","w");fputs("abc",fp);fclose(f
有三个关系R、S和T如下:由关系R和S通过运算得到关系T,则所使用的运算为
下面不能作为结构化方法软件需求分析工具的是()。
随机试题
Thenewsaboutvitaminskeepsgettingworse.Manystudiespublishedinthelastfewyearsshowsthatavarietyofpopularsupple
初产妇,外阴发育较差,自娩一活婴。产后2小时即感伤口疼痛难忍,里急后重,大便1次,黄稀状,镜检WBC0~1个/HP,少许黏液。查体:血压90/60mmHg,阴道出血不多,贫血貌。对此患者应采取什么措施
病原体更换宿主的过程称为
患者,女,慢性支气管炎入院,医嘱氧气雾化吸入。以下步骤不妥的是
某企业存货的日常核算采用毛利牢法汁箅发出存货成本。该企业2012年1月份实际毛利率为30%,本年度2月1日的存货成本为600万元,2月份购入存货成本为l400万元,销售收入为1350元。该食业2月术存货成本为()万元。
在母语的屋檐下少年时代的伙伴自大洋彼岸归来探亲,多年未见,把盏竟夜长谈。我们聊到故乡种种情形,特别谈到了家乡方言,兴之所至,后来俩人干脆用家乡话谈起来。本来以为这么多年不使用,很多方言都已忘记,不料却在此时鲜明地复活了。恍惚中,甚至忆起
村民甲(18周岁)路过村民乙家门口时,用一块石头向乙家所养且卧在乙家门口的狗打去,该狗立即扑向甲,甲因跑得快未被狗咬,狗咬伤了甲旁边的行人丙。丙因躲避,将路边丁叫卖的西瓜踩碎三个。丙因治伤支付医药费80元。丁的三个西瓜价值16元。丙、丁的损失应由谁赔偿?(
填入下列横线处恰当的是:广场上,悠扬的琴声如一股甜蜜的气息________,周围林立的参天大树里,低矮的灌木丛里,朵朵盛开的月季里,都像流淌和分泌着音符。
将考生文件夹下CREAM文件夹中的SOUP文件夹删除。
Friendshipisunconditionalanduncritical,basedonlyonmutualrespectandtheabilitytoenjoyeachother’scompany.Theseau
最新回复
(
0
)