Recently I am studying operating system..I just wanna know:
What’s the difference between a system call (like write()) and a standard library function (like printf()
I am writing a small program. At the moment it just reads each line from stdin and prints it to stdout. I can add a call to write in the loop, and it would add a few characters at the end of each line. But when I use printf instead, then all the extra characters are clustered and appear all at once, instead of appearing on each line.
It seems that using printf causes stderr to be buffered. Adding fflush(stdout);
after calling printf fixes the discrepancy in output.