</>EmbeddedInterview

Remove spaces from a string in place.

Easy"Coding: Memory & String Functions"
void remove_spaces(char *s)
{
    char *w = s;                       /* write pointer */
    for (char *r = s; *r; r++)         /* read pointer */
        if (*r != ' ') *w++ = *r;
    *w = '\0';
}
/* "a b  c" -> "abc" */

Points: two pointers, one pass, O(1) extra space; terminate at the new end. Same pattern removes any character or all whitespace (isspace).