gcc - Why does an infinite loop block a printf statement earlier in my C program? -


this question has answer here:

this c program prints done, enters infinite loop.

#include <stdio.h>  int main(int argc, char const *argv[]) {     printf("done");     while (1) {}     return 0; } 

but when run it, code not print done. why that?

it needs flush buffer. console output doesn't flush until receives '\n'.

there's little-used function this, fflush().

#include <stdio.h>  int main(int argc, char const *argv[]) {     printf("done");     fflush(stdout);     while (1) {}     return 0; } 

that should print you.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -