why such output is coming?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bajajv
    New Member
    • Jun 2007
    • 152

    #1

    why such output is coming?

    Hi,
    I got this code from a c puzzles site. Not able to figure out, why such output is coming.

    Code:
    #include <stdio.h>
    #include <unistd.h>
    int main()  
    {          
        while(1)          
        {
           fprintf(stdout,"hello-out");                     
                      
           fprintf(stderr, "hello-err")
           sleep(1);          
        }          
    return 0;  
    }
    This code doesn't prints hello-out. The output is -
    hello-errhello-errhello-err.....
    What could be the reason?
  • newb16
    Contributor
    • Jul 2008
    • 687

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

    Comment

    • bajajv
      New Member
      • Jun 2007
      • 152

      #3
      Well yes.. its working this way.. thanks..:)

      Comment

      Working...