My favourite debugging technique is to get in there with a debugger, or failing that to sprinkle printf statements liberally across the code to display variables and why we are where we are, and find out what the program is *actually* doing. If you try debugging code based on what you *think* it's doing then you'll get nowhere, because you'll always think the code is doing what you were thinking when you wrote it - hence you not realising that ++ was in the wrong place.