(1) Please use code blocks.
(2) The problem may not be in the code you've posted. Create a testbed that calls this from a simple main() function and make sure that reproduces the problem. If it does then post the new code here WITH CODE BLOCKS and we can have a look.

Out of interest, does the maximum line length of 16 characters include room for end of line and terminating NULL? So if you have the string "Hello\n" for example, that's actually 7 characters, and if you mean the "Hello" part is limited to 16 characters then you need larger arrays than just [16].