删除字符串中指定字符

来源:百度知道 编辑:UC知道 时间:2024/05/14 19:47:25
输入两个字符串 s1 和 s2 ,在 s1 中删除任何 s2 中有的字符。例如, s1 :“ abc123ad ”, s2 :“ a1 ” ,则输出“bc23d ”。

输入: 两个字符串 s1 和 s2

输出: 删除后的字符串 s1

例如:
输入:abc123ad
a1
输出:bc23d

#include <stdio.h>
#include <string.h>
void main()
{
char s1[100],s2[100];
int i,j,k;
char temp;
printf("Please input 2 string:\n");
gets(s1);
gets(s2);
for(i=0;i<strlen(s2);i++)
{
temp=s2[i];
j=0;
while(s1[j]!='\0')
{
if(s1[j]==temp)
{
k=j;
while(s1[k]!='\0')
{
s1[k]=s1[k+1];
k++;
}
}
j++;
}
}
printf("The result is:\n");
puts(s1);
}