BUFSIZ - C stdio.h

C examples for stdio.h:BUFSIZ

Type

constant

From

<cstdio>
stdio.h

Description

BUFSIZ is a macro defined in stdio.h.

It is an integer value for the size of the buffer used by the setbuf function.

Demo Code

#include <stdio.h>

int main (){/*from w  w  w .  j  a v  a  2  s . c  om*/

  printf("%u",BUFSIZ);

  char buffer[BUFSIZ];
  FILE *pFile1, *pFile2;

  pFile1=fopen ("main.cpp","w");
  pFile2=fopen ("myfile2.txt","a");

  setbuf ( pFile1 , buffer );
  fputs ("a buffered stream",pFile1);
  fputs ("a buffered stream",pFile1);
  fputs ("a buffered stream",pFile1);
  fputs ("a buffered stream",pFile1);
  fflush (pFile1);

  setbuf ( pFile2 , NULL );
  fputs ("an unbuffered stream",pFile2);
  fputs ("an unbuffered stream",pFile2);
  fputs ("an unbuffered stream",pFile2);
  fputs ("an unbuffered stream",pFile2);

  fclose (pFile1);
  fclose (pFile2);

  return 0;
}

Related Tutorials