
提问人:网友13***556
发布时间:2022年4月22日 23:08
[单选题]
下列给定程序中函数fun的功能是:将s所指字符串中最后一次出现的与t1所指字符串相同的子串替换成t2所指字符串,所形成的新串放在w所指的数组中。要求t1和t2所指字符串的长度相同。例如,当s所指字符串中的内容为:"abcdabfabc",t1所指串中的内容为"ab",t2所指子串中的内容为"99"时,结果在w所指的数组中的内容应为"abcdabf99c"。#include
下列给定程序中函数fun的功能是:将s所指字符串中最后一次出现的与t1所指字符串相同的子串替换成t2所指字符串,所形成的新串放在w所指的数组中。要求t1和t2所指字符串的长度相同。例如,当s所指字符串中的内容为:"abcdabfabc",t1所指串中的内容为"ab",t2所指子串中的内容为"99"时,结果在w所指的数组中的内容应为"abcdabf99c"。#include #include void fun (char *s, char *t1, char *t2 , char *w){ char *p , *r, *a; strcpy( w, s );/************found************/ ____________ { p = w; r = t1; while ( *r ) 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[100], t2[100], w[100]; 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("\nError : strlen(t1) != strlen(t2)\n");}
A . while (*w)B . while (w)C . while (*r)D . while (r)

