I saw this in a \"list of interview questions\". Got me wondering.
Not limited to whitespace necessarily, of course, easily generalized to \"removing some specific char
First of all, i
str[i]
, i.e. loop until str[i]
is the null terminator.
With that said, here's the simplest/most concise algorithm I know:
for (size_t i=0, j=0; s[j]=s[i]; j+=!isspace(s[i++]));
Note: My solution is for the question as written in the subject (whitespace) as opposed to the body (particular character). You can easily adapt it if needed.