I'm guessing in the editing of your long code, that you've managed to snip some scanf() calls before that loop is entered.

Use fgets() for ALL input (don't mix and match, it's usually a disaster)....