Home > database >  using printf and write together
using printf and write together

Time:04-20

I would like to understand why when I execute this code

#include <stdio.h>
#include <unistd.h>

int main()
{
    write(1, "6", 1);
    printf(" | ");
    write(1, "6", 1);
}

I get this output

66 | %

Instead of

6 | 6%

even with sleep before and after the printf it doesn't fix it. Thanks

CodePudding user response:

Try fflush(stdout); The file I/O is buffered to improve performance. Fflush write the buffers out. Mixing the 2 may still give you surprises, so I would not recommend doing it.

  • Related