Yes, you're going past the end of the string when you're incrementing "n++" after the for-loop in the main. So if you find a nul-character in the string, you go past it, and continue until the next nul, which may be overflowing all sorts of other buffers and cause bad thing to happen. See one of my previous posts.
--
Mats