Problem of the Day
A new programming or logic puzzle every Mon-Fri

Whitespace Removal

Today's goal is to create a program that removes all the whitespace from a string. The trick is you must do it in place (without creating another copy of the string). If you want to use a language where strings are immutable just simple overwrite the string when needed.

Permalink: http://problemotd.com/problem/whitespace-removal/

Comments:

  • Anonymous - 10 years ago

    void removeWhiteSpace(char *cPtr) { while (*cPtr) { if (*cPtr == ' ') { strcpy(cPtr, cPtr+1); } cPtr++; } }

    reply permalink

Content curated by @MaxBurstein