Remove whitespace from a string in-place, in linear time

Should not there be a \o in the end to terminate t…

Neha - Oct 2, 2013

Should not there be a \o in the end to terminate the string??

Yes this is a ‘\0’ terminated string only. We are moving ahead only when we find a white space (when we say):
while (str[ahead] == ' ‘) ahead++;

Rest all the characters except the space are copied as is, which also includes ‘\0’ and hence string is ‘\0’ . Please let me know if you don’t agree with me. :)


See also