By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,335 Members | 2,281 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,335 IT Pros & Developers. It's quick & easy.

why such output is coming?

bajajv
100+
P: 152
Hi,
I got this code from a c puzzles site. Not able to figure out, why such output is coming.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. int main()  
  4. {          
  5.     while(1)          
  6.     {
  7.        fprintf(stdout,"hello-out");                     
  8.  
  9.        fprintf(stderr, "hello-err")
  10.        sleep(1);          
  11.     }          
  12. return 0;  
  13. }
  14.  
This code doesn't prints hello-out. The output is -
hello-errhello-errhello-err.....
What could be the reason?
Aug 26 '10 #1

✓ answered by newb16

may be stdout waits for a newline to flush. ( try "hello-out\n" )

Share this Question
Share on Google+
2 Replies


100+
P: 687
may be stdout waits for a newline to flush. ( try "hello-out\n" )
Aug 26 '10 #2

bajajv
100+
P: 152
Well yes.. its working this way.. thanks..:)
Aug 26 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.