Table of Contents

setbuf

    void setbuf(FILE *stream, char *buffer);

Controls buffering for stream stream. For null buf, turns off buffering, otherwise equivalent to (void)setvbuf(stream, buf, _IOFBF, BUFSIZ).

setbuf is deprecated use setvbuf instead

C Sourcecode Example

/* 
 * setbuf example code
 * http://code-reference.com/c/stdio.h/setbuf 
 */
 
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
 
 
int main( void )
{
  FILE *stream = fopen("test.txt", "w");
  FILE *stream2 = fopen("test2.txt","w");
 
  char buffer[100];
  char buffer2[BUFSIZ];  
 
  setbuf(stream, buffer);
  fputs("Buffered input for test.txt", stream);
  fflush(stream);
  fclose(stream);
 
  setbuf(stream2, buffer2);
  fputs("Buffered input for test2.txt", stream2);
  fflush(stream2);
  fclose(stream2);
 
  return 0;
}
  output: ./setbuf
  

content of test.txt

Buffered input for test.txt

content of test2.txt

Buffered input for test2.txt