I am confused about scanf\'s behaviour in the following program. scanf appears to input once, and then not input again, until a stream of characters is printed.
You are ignoring the return value. See what the manual says about scanf(3):
RETURN VALUE These functions return the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure.