That's because when user enters his security number, he actually enters 12 or 13 characters - 11 for security number and one or two is the CRLF or just LF. You're reading only eleven, so CRLF is still in buffer when you trying to read EDP number, so readline getting end of security number line and returns it. Just use readline also for reading security number and it will remove CRLF from the buffer, you can check length and correctness of entered number later.