Do not mix buffered output and unbuffured output (printf and write).