#include<stdio.h>
void squeeze(char *s1,char *s2);
main()
{
char *s1="string";
char *s2="spring";
squeeze(s1,s2);
printf("%s",s1);
}
void squeeze(char *s1,char *s2)
{
int i=0,j=0,k=0,bool=1;
for(i=0,k=0;s1[i]!='\0';i++)
{
for(j=0;s2[j]!='\0';j++)
if(s1[i]==s2[j])
{
bool=0;
break;
}
if(bool)
{
s1[k++]=s1[i];
}
bool=1;
}
s1[k]='\0';
}
this program gave me a seg fault.i tried debugging it with gdb. the error is in line 25
(i.e) s1[k++]=s1[i];
i tried running the same function in java. suprisingly it was working well.i replaced the pointers with arrays and exit the loop when the looper is equal to array length.but it wont work on c any suggestions? thanks