So if A="aBcDeFg" and B="BDF", the output should be "aceg".
My idea was to check one-by-one if character of A is equal with any character of B (A[0] vs B[0]/B[1]...B[n] and so on). Therefore if they do not match, a counter variable is incremented. If the counter is smaller than length of B, then this character is deleted and when the counter equals length of B, the character is moved in an other string.
My version looks like this, but is not working:
void remove_characters(char s[], char r[])
{
int k, i, j, l = 0;
char s_copy[20];
for (i = 0; s[i] != '\0'; i++){
for (j = 0; r[j] != '\0'; j++)
if (s[i] != r[j])
k++;
if (k = strlen(r)){
s_copy[l++] = s[i];
k = 0;
}
}
puts(s_copy);
}
void main()
{
char s1[20],s2[20];
printf("Enter the first string: ");
gets(s1);
printf("Enter the second string: ");
gets(s2);
remove_characters(s1,s2);
}
Any ideas where is the problem?