#include
#include
int main()
{
int choose,i;
char x[100],p1,p2;
printf("输入一个字符串:");
gets(x);
printf("选择 1 替换或 2 消除:");
scanf("%d",&choose);
switch (choose)
{
case 1:
{
printf("要替换的字母:");
getchar();
scanf("%c",&p1);
printf("替换成为:");
getchar();
scanf("%c", &p2);
for (i = 0; i < strlen(x);i++)
if (x[i] == p1)
x[i] = p2;
printf("新字符串:");
puts(x);
break;
}
case 2:
{
printf("要消除的字母:");
getchar();
scanf("%c",&p1);
for (i = 0; i < strlen(x);i++)
if (x[i] == p1)
memmove(x+i,x+i+1,strlen(x)+1-i);
puts(x);
break;
}
}
return 0;
}
#include
int main()
{
char a[50],g,d;
gets(a);
scanf("%c\n%c",a,&g,&d);
char *p=a;
while(*p!='\0'){if(*p==g) *p=d;p++;}
puts(a);
return 0;
}