setbuf

associate a buffer with a file

Synopsis:

#include <stdio.h>
void setbuf( FILE *fp, char *buffer );

Description:

The setbuf() function can be used to associate a buffer with the file designated by fp. If this function is used, it must be called after the file has been opened, and before it has been read or written. If the argument buffer is NULL, then all input/output for the file fp will be completely unbuffered. If the argument buffer is not NULL, then it must point to an array that is at least BUFSIZ characters in length, and all input/output will be fully buffered.

See also:

fopen(), setvbuf()

Examples:

#include <stdio.h>
#include <stdlib.h>

void main()
  {
    char *buffer;
    FILE *fp;

    fp = fopen( "file", "r" );
    buffer = (char *) malloc( BUFSIZ );
    setbuf( fp, buffer );
    /* . */
    /* . */
    /* . */
    fclose( fp );
  }

Classification:

ANSI

Systems:

All (except DOS/PM)