Not that this is entirely related, but it's always a good idea to check the return value of scanf when it's used.