Encoders
Hub for Computer Whizzes Register to join us

Encoders > More... > C > Program

/* Function squeeze(s1,s2) that deletes each character in the first string
   that matches any character in the second string. */

#include <stdio.h>

void squeeze(char string1[], char string2[]);

main()
{
        char a[]="hello world",b[]="apple";
	squeeze(a,b);
	puts(a);
}

void squeeze(char s1[], char s2[])
{
	int i,j,k;
	for(i=0; s2[i]!='\0'; i++)
	{
		for(k=j=0; s1[j]!='\0'; j++)
			if(s1[j]!=s2[i])
				s1[k++]=s1[j];
		s1[k]='\0';
	}
}