in reply to sprintf is printing unexepected output

On a somewhat unrelated note, it's a bit redundant to say print sprintf(...). You can just use printf.