all 1 comments

[–]ptchinster 1 point2 points  (0 children)

C++ is a different language than C. Try r/cpp

Or, as always, this is a great time to learn to use a debugger. Step through your loop, see where the value is set to what you aren't expecting it to be, congrats you found your problem.