0

What is the difference between read() and fread()?

I've read several questions about read and fread and every answer claims read is unbuffered, but read function also has buffer parameter ssize_t read(int fd, void *buf, size_t count), same thing with write and fwrite, for example:

#include    <stdio.h>
#include    <unistd.h>
#include    <string.h>
#include    <errno.h>
 
int main(int argc,char**argv)
{
    char buffer[]="hello world";
    
    printf("%s",buffer);
     
    // buffered
    fwrite(buffer, strlen(buf), 1, stdout);
    
    // unbuffered?
    write(STDOUT_FILENO, &buf, strlen(buf));
    
    return(0);
}

Why are read and write unbuffered?

mzoz
  • 1,117
  • 1
  • 12
  • 23

0 Answers0