This is the code that I came up with, but sometimes it does not work.
For example, if string1 = highway to hell, and string2 = stairway to heaven, the output is 'ghll' despite 'h' being in the second string as well as the first string. I cant figure out why h is not being removed like other characters that are in both strings.
#include <stdio.h>
#include <string.h>
main()
{
char string1[30], string2[30];
int length1, length2;
printf("Enter string 1: ");
gets(string1);
printf("Enter string 2: ");
gets(string2);
length1 = strlen(string1);
length2 = strlen(string2);
for (int i = 0; i <= length1; i++)
{
for (int j = 0; j <= length2; j++)
{
if (string1[j] == string2[i])
{
for (int k = j; k <= length1; k++)
{
string1[k] = string1[k + 1];
}
}
}
}
printf("Deleted characters of string 2 from string 1: %s", string1);
}