Why couldn't I work with the gcc compiler without '\ n' in printf?

I wrote an instruction printf()as shown below:

printf("hello\n");

this works great when built using the Linux gcc compiler. However, if I write

printf("hello");

Printing does not appear on the screen. Does it seem to have some kind of buffer mechanism? Can someone give me more info about this?

+3
source share
3 answers

Even if buffering is not a problem, if you are not printing a new line, prompting your shell may discard the output.

, , , , gcc unix, printf ( "" ), . , , .

+7

fflush(). , , . A\n , ( ), - .

+14

here IO .

c- setvbuf

setvbuf(stdout, (char *)NULL, _IONBF, 0); //unbuffered stdout
+2
source

Source: https://habr.com/ru/post/1717431/


All Articles