Yeah, I had almost exactly the same code. I'm sure most people did too. The only other "obvious" algorithm is the n^2 one.
Edit: Correction... I also copy the '\0' character before exiting instead of making that a separate step. It has to do with the order of things. Here is the code:
char* read_ptr = s;
do {
if (*read_ptr != c) {
*s++ = *read_ptr;
}
} while (*read_ptr++ != '\0'); void condense_by_removing( char *z_terminated , char char_to_remove)
{
char * sp;
char * dp;
sp = dp = z_terminated;
while (*sp != '\0') {
while (*sp == char_to_remove){
sp++;
}
*dp = *sp;
dp++;
sp++;
}
*dp = *sp;
}