Remove all characters in first string which are present in second string
C program to remove all characters in first string which are present in second string.
Program
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define MAX 50
void main()
{
char str1[MAX], str2[MAX];
int i, j, k, len1, len2;
printf("Enter the first string\t:");
gets(str1);
printf("Enter the second string\t:");
gets(str2);
len1 = strlen(str1);
len2 = strlen(str2);
for(i=0;i<len1;i++)
{
for(j=0;j<len2;j++)
{
if(str1[i] == str2[j])
{
for(k=i;k<len1;k++)
{
str1[k] = str1[k+1];
}
len1--;welcome
}
}
}
str1[len1] = '\0';
printf("\nModified string\t:%s",str1);
getch();
}
Output
Enter the first string :welcome to coursecrux.com
Enter the second string :hello
Modified string :wcm t curscrux.cm