Nevermind, problem resolved. Sorry for wasting time. Your suggestion to learn debugging helped a ton! I never knew you could follow variables throughout a program like that.
What compiler / IDE? Have you used the debugger yet? This is the type of problem that should be very simple to debug. You have to step through the code line by line in the debugger while analyzing the state of all variables as you go. I didn't see anything obvious at first glance but I think it is really important for you to attempt to debug yourself and share any relevant findings to the board. If you tell us what IDE you are using (codeblocks, visual studio express, etc.) someone could probably give you some pointers on getting started with that.