4 ms·
Turns out his solution is almost the same as mine except I skip the termination stage and instead read one character more in the loop which catches the \0 from
by petercooper 16y ago
Turns out his solution is almost the same as mine except I skip the termination stage and instead read one character more in the loop which catches the \0 from the original end of the string automatically. As I'm not really a C programmer, was I doing something bad/unrecommended? It seemed to work.. :-)
- RiderOfGiraffes 16y agoDo you want to email me your reference number and I'll have a chat about it. It would be useful for me to clarify the next article on this point.
- zb 16y agoWhat happens if you pass '\0' as the character to remove?
- ydant 16y agoLike the grandparent, I do the same. I have the copy routine also copy over the final 0. If you pass in 0 as the character to remove, it still works fine. Nothing is shifted, so the final 0 is copied and the string remains null terminated. Technically this could be undesirable behavior (it's contrary to the spec), but I don't think the behavior if you do pass in a 0 to remove could be easily defined. What does it copy into the place where the null was? How does it know where to stop? Easier to just assume it's remove any non-null character and asking to remove null means remove nothing.