[b][size=2]将已知字符串S中所有属于字符串S1中的字符都用S2中的对应字符代替。
#include <stdio.h>
#define MAX 50
rep(char *s,char *s1,char *s2)
{char *p;
 for(;*s;s++)   
 {
 for(p=s1;*p&&*p!=*s;p++)
 if(*p)*s=*(p-s1+s2);
 }
}
main()
{
char s[MAX];
char s1[MAX],s2[MAX];
clrscr();
puts("Please input the string for s:");
scanf("%s",s);
puts("Please input the string for s1:");
scanf("%s",s1);
puts("Please input the string for s2:");
scanf("%s",s2);
rep(s,s1,s2);
puts("The string of s after displace is:");
printf("%s\n",s);
puts("\n press any key to quit...");
getch();
}
程序结果不对(反过来了把s1出现的字符之外的全变成s2的字符啦)不明白这几行代码是什么意思:
 for(;*s;s++)   
 {
 for(p=s1;*p&&*p!=*s;p++)
 if(*p)*s=*(p-s1+s2);
 }
请大家解释一下!要怎么改回来呢?[/size][/b]