Re:Interviewing programmers: coding test example explained
by petercooper on Thursday June 03, 2010 @11:21AM
(#1401543)
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.. :-)
[ Parent
| on HN ]
Re:Interviewing programmers: coding test example explained
by zb on Thursday June 03, 2010 @12:34PM
(#1401757)
What happens if you pass '\0' as the character to remove?
Re:Interviewing programmers: coding test example explained
by ydant on Thursday June 03, 2010 @02:21PM
(#1402039)
Like 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.
Re:Interviewing programmers: coding test example explained
by RiderOfGiraffes on Thursday June 03, 2010 @11:26AM
(#1401563)
Do 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.