I use this as my interview question, and I have seen scores of various ways to do it wrong.

Recently, however, I've got a spectacular recovery from a gentleman I was talking to.

He initially wrote something along the lines of

\nvoid removeSpaces(char *s)\n{\n    for (;*s != 0; s++) {\n        if (isspace(*s))\n           *s = *(++s);\n    }\n}\n


So, I wrote two strings "a<space><space>b" and "a<space>".

And then he goes, "Ahh, I should make it recursive!"

In the end, he's got something along the lines of
\nvoid removeSpaces(char *s)\n{\n    for (;*s != 0; s++) {\n        if (isspace(*s)){\n          *s = *(++s);\n          removeSpaces(s);\n          return;\n        }\n    }\n}\n



I think that's amazing. If the compiler supports tail recursion, it will even be cheap and safe WRT stack overflow, I think.