下列给定的程序中,函数fun( )的功能是;将s所指字符串中出现的n所指字符串全部替换成t2所指字符串,所形成的新的字符串放在w所指的数组中。在此处,要求t1和t2所指字符串的长度相同。例如:当s所指字符串中所指的内容为 abcdabfab,t1所指字符串中的内容为ab,t2所指字符串中的内容为99时,结果在w所指的数组中的内容应为99cd99f99。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
/*************found**************/
int fun (char *s, char *t1, char *t2, char *w)

int i; 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;
/*************found**************/
while (*r)*a=*r;a++;r++
w+=strlen(t2);

else w++;

main( )
char s[100],t1[100],t2[100],w[100];
clrscr( );
printf("/nPlease enter string S: ");
scanf("%s",s);
printf("/nPleaseentersubstring 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");

题库:计算机等级考试 类型:填空题 时间:2017-07-03 15:11:48 免费下载:《填空》Word试卷

下列给定的程序中,函数fun( )的功能是;将s所指字符串中出现的n所指字符串全部替换成t2所指字符串,所形成的新的字符串放在w所指的数组中。在此处,要求t1和t2所指字符串的长度相同。例如:当s所指字符串中所指的内容为 abcdabfab,t1所指字符串中的内容为ab,t2所指字符串中的内容为99时,结果在w所指的数组中的内容应为99cd99f99。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <string.h>
/*************found**************/
int fun (char *s, char *t1, char *t2, char *w)

int i; 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;
/*************found**************/
while (*r)*a=*r;a++;r++
w+=strlen(t2);

else w++;

main( )
char s[100],t1[100],t2[100],w[100];
clrscr( );
printf("/nPlease enter string S: ");
scanf("%s",s);
printf("/nPleaseentersubstring 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");

下列给定的程序中,函数fun( )的功能是;将s所指字符串中出现的n所指字符串全部替换成t2所指字符串,所形成的新的字符串放在w所指的数组中。在此处,要求t1和

本题关键词:数字字符串,符号数字试验,串珠肋,串级式,串料法,串联式,四个成串刺激,黑龙串筋,串联系统,分区串联;

微信扫码获取答案解析
下载APP查看答案解析