|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
1. 以下程序中函数replace的功能是:将字符串s中所有属于字符串s1中的字符都用s2中的对应位置的字符替换。假如s为“ABCBA”,s1为“AC”,s2为“ac”,则调用replace函数后,字符串s的内容将变换为“aBcBa”。试完善程序以达到要求的功能。
#include <stdio.h>
#define MAX 20
void replace(char *s, char *s1, char *s2)
{ char *p;
for(; *s; s++)
{ p=s1;
while(*p&& (1) ) p++;
if(*p) *s= (2) ;
}
}
void main( )
{ char s[MAX]="ABCBA",s1[MAX]="AC", s2[MAX]= "ac";
replace(s, s1, s2);
printf("The string of s is:");
printf("%s\n", s);
}
帮忙填一填空
(1) *p != *s (2) *(s2+ p- s1)
网上直接搜就好了https://wenku.baidu.com/view/49fa8605864769eae009581b6bd97f192279bf62.html
|
|