Code:
void squeeze(char s1[], char s2[])
{
int i,j,k;
for(i = k = 0; s1[i] != '\0'; i++)
{
for(j = 0; s2[j] != '\0' && s2[j] != s1[i]; j++)
;
if (s1[j] == '\0')
s1[k++] = s1[i];
}
s1[k] = '\0';
}
im havin trouble understanding this piece of code. i know what it does. it deletes, in s1[], whatever occurs in s2[]. ive been at this k&r exercise for a while and cheated by looking at the answer book. yet i still dont understand the concept of this function. the for loop, i know, steps through each array element and tests. and while s2[j] != s1[i], j keeps incrementing. but once it reaches a match, what happens?
Code:
if (s2[j] == '\0')
s1[k++] = s1[i];
if it reaches a match before the actual '\0' what happens? thanks in advance for response. and sorry if this post seemed a little long-winded. just trying to understand everything. =)