Why does a call to printf need to be terminated by a newline ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-02-02 12:57 AM
Works:
printf("hello world\n");
Does not work:
printf("goodbye world !");
I have tried to find the answer in gcc´without success.
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-02-02 1:25 AM
That is a standard properity of stdout, it is buffered. Use stderr and output is immediate.Or fflush stdout.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-02-02 1:25 AM
That is a standard properity of stdout, it is buffered. Use stderr and output is immediate.Or fflush stdout.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-02-02 1:33 AM
It doesn't need to. But, by default printf is line buffered. This allows more efficient output if you override _write (instead of __io_putchar). It is also for historical reasons/compatability.
If you want to turn it off:
setvbuf(stdout, NULL, _IONBF, 0);
hth
KnarfB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-02-02 7:17 AM
Thanks alot.
