delete matching characters from string
Hi everyone, Would someone be able to explain to me why the "if statement" and "s1[k] = '\0';" is necessary in the code. It works fine with just the two for loops. But i dont understand the reason for the if statement and setting "s1[k] to '\0', when i can just add a print statement to the second loop: printf("%c\n", s1[i]; The program below skips over chars from string1 that match any chars from string string2. Appreciate any help. Thank you. void squeeze(char s1[], char s2[]) { int i, j, k; int len1 = strlen(s1); int len2 = strlen(s2); for (i = k = 0; i < len1; i++) { for (j = 0; (s1[i] != s2[j]) && j < len2; j++) ; if (s2[j] == '\0') { s1[k++] = s1[i]; } } s1[k] = '\0'; }