Hello.
i wrote a program to do the following:
Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted.
This is what i tried:
void trimString()
{
char s1[] = "hello world";
char s2[] = "el";
int i, j;
for (i = 0; i < (signed)strlen(s1); i++) {
for (j = 0; j < (signed)strlen(s2); j++) {
if (s1[i] == s2[j]) {
s1[i] = -1;
break;
}
}
}
for (i = 0, j = 0; i < (signed)strlen(s1); i++) {
if (s1[i] != -1) {
s1[j] = s1[i];
j++;
}
}
s1[j] = '\0';
printf("\nString is%s", s1);
}
Can i further improve it in any way?
Thanks.