首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下列给定程序中,函数fun的功能是:将s所指字符串中最后一次出现的与t1所指字符串相同的子串替换成t2所指字符串,所形成的新串放在w所指的数组中。要求t1和t2所指字符串的长度相同。 例如,当8所指字符串中的内容为“abcdab. fabc”,t1
下列给定程序中,函数fun的功能是:将s所指字符串中最后一次出现的与t1所指字符串相同的子串替换成t2所指字符串,所形成的新串放在w所指的数组中。要求t1和t2所指字符串的长度相同。 例如,当8所指字符串中的内容为“abcdab. fabc”,t1
admin
2017-09-23
24
问题
下列给定程序中,函数fun的功能是:将s所指字符串中最后一次出现的与t1所指字符串相同的子串替换成t2所指字符串,所形成的新串放在w所指的数组中。要求t1和t2所指字符串的长度相同。
例如,当8所指字符串中的内容为“abcdab. fabc”,t1所指串中的内容为“ab”,t2所指子串中的内容为“99”时,结果在w所指的数组中的内容应为 “abcdabt99c”。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include < conio.h >
#include < stdio.h >
#include < string.h >
void fun(char *s,char t1,chart2,char w)
{
char *p,*r,*a;
strcpy(w,s);
/*********found*********/
while(w)
{
p=W;
r=t1;
while(*r)
/*********found*********/
IF(* r==*p)
{
r++;
p++;
}
else
{
break;
}
if(*r==’\0’)
a=w;
w++;
}
r=t2;
while(*r)
{
*a=*r;
a++;
r++;
}
}
main()
{
char s[100],t1[1 00],t2
[100],w[100];
printf("\nPlease enter
string S:");
Scanf("%s",s);
printf("\nPlease enter
substring t1:");
scanf("%s",t1);
print f("\nPlease enter
substring t2:");
scanf("%s",t2);
if(str1en(t1)==str1en(t2))
{
fun(s,t1,t2,w);
printf ("\nThe result
is:%s、n",w);
}
else
{
printf("\nError:
str1en(ti)!=str1en(t2)\n");
}
}
选项
答案
(1)while(*w) (2)if(*r== *p)
解析
(1)此处要判断的是值的真假,而不是地址,所以改为while(*w)。
(2)C语言中关键字区分大小写,只需运行程序,就可以根据错误提示找到。
转载请注明原文地址:https://kaotiyun.com/show/xoxp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
下列程序的运行结果是()。#include<stdio.h>voidfun(int*s,int*p){staticintt=3;*p=s[t];t--;}voidmain(){
函数rewind(fp))的作用是()。
下列程序的运行结果是()。#include<stdio.h>voidsub(int*s,int*y){staticintm=4;*y=s[0];m++;}voidmain(){
以下有关宏替换的叙述不正确的是()。
以下能正确定义字符串的语句是()。
在下列关系运算中,不改变关系表中的属性个数但能减少元组个数的是()。
设变量已正确定义并赋值,以下正确的表达式是()。
以下选项中不合法的标识符是()。
下面的程序在编译时产生错误,其出错原因是()。#includemain(){intlcase;floatprintF;printf(“请输入2个数:”);scanf(“%d%f”,&1
下列选项中可作为C语言合法常量的是()。
随机试题
下列资产中属于可辨认无形资产的是( )。
独立的木材加工厂与周围其他设施、建筑之间的安全防火距离不小于()m。
某社会团体与某私立学校共同出资设立一合伙企业,经营文具用品。两年后,因经营亏损,该合伙企业财产不足以清偿全部债务。下列关于各合伙人承担责任的表述中,符合《合伙企业法》规定的有()。
报告属于陈述性的上行公文。()
我国古代文人在诗词中常运用典故表达自己的思想感受,下列作品中没有使用典故的是()。
“泉”是_____。
简述自然人民事行为能力的种类。
物理层传输的是(63)。
Itissaidthatmorethanoneorganization______inthiswell-knowncriminalcase.
【B1】【B17】
最新回复
(
0
)