Name:
Anonymous
2007-05-11 16:50
ID:tCgeez6Q
I receive a string, and I want to remove any 'a', 'b' and 'c' characters, in a recursive way.
How do I do this in C and Java?
Thanks
Name:
Anonymous
2007-05-17 16:43
ID:+Ug3t86q
This is the correct way to do it iteratively in C:
//Null terminated strings 'str' and 'rem'
char *strrem(char *str, const char *rem) {
char *ip, *sp, *rp;
if (str && *str && rem && *rem) {
for (ip = sp = str; *sp; ++sp) {
for (rp = (char *) rem; *rp; ++rp) {
if (*sp == *rp) {
break;
}
}
if (!*rp) {
*ip++ = *sp;
}
}
while (*ip) {
*ip++ = '\0';
}
}
return str;
}
I'll leave it to you to find the recursive version which isn't terribly difficult to find.