What is the easiest and most efficient way to remove spaces from a string in C?
Easiest and most efficient don't usually go together…
Here's a possible solution for in-place removal:
void remove_spaces(char* s) { char* d = s; do { while (*d == ' ') { ++d; } } while (*s++ = *d++); }
2.1m questions
2.1m answers
60 comments
57.0k users