printf() prints string without newline to stdout in line buffer mode after scanf()
<p>I am aware that most terminals are by default in line buffer mode. i.e. output is buffered and not directed to stdout until a new-line character is encountered.</p>

<p>So I would expect this to print nothing (at least before the buffer is filled up):</p>

<pre><code>int main() {
    while(1) {
        printf("Haha");
        sleep(1);
    }
    return 0;
}
</code></pre>

<p>It indeed prints nothing for a short period of time.</p>

<p>If I want to print "Haha" every second, I can either <code>printf("Haha\n")</code> or do <code>fflush(stdout)</code> after printf. (I know this is not so portable, but it's a solution nonetheless)</p>

<p>Now I recall the very classic scanf program (with my addition to while(1) loop to prevent buffer flushing on program exit):</p>

<pre><code>int main() {
    char char_in;
    while(1) {
        printf("Haha. Input sth here: ");
        scanf("%c", &amp;char_in);
    }
    return 0;
}
</code></pre>

<p>Now the program prints <code>Haha. Input sth here:</code> (and wait for my input). It is not here if I remove the scanf statement. Why is that so?</p>

<p>Thanks.</p>