Ex. 2-4 KnR (2nd ed.) loop && array handling
Heyyy, I'm on exercise 2-4 in k&r 2nd ed.
(Its getting kinda funky but I'm keeping with)
Ex: Write an alternate version of squeeze(s 1, s2) that deletes each character in s1 that matches any character in string s2.
I started off (trying) to copy every non-matching character into a third array. But the loop wasn't working.
So now, I'm trying to fix my error and print a 'Z' insted of deleting.
Code:
void squeeze1(char s[], char t[]) {
int i, j ;
for (i = 0; s[i] != '\0'; i++) {
for (j = 0; t[j] != '\0'; j++)
if (s[i] == t[j])
s[i] = 'Z';
}
for (i = 0; s[i] != '\0'; i++)
printf("%c", s[i]);
}
My understanding is that the parent loop initiates, encounters the child loop, completes the child loop and exits (For each element in s, compare to every element in t).
Can anyone show me where I've gone wrong. TIA