Use C setvbuf function to set buffer stream

Syntax

C setvbuf function has the following syntax.

int setvbuf(FILE *stream, char *buf, int mode, size_t size);

C setvbuf function is from header file stdio.h.

Description

C setvbuf function sets the buffer for stream to be buffer, with a size of size.

C setvbuf function returns zero on success, nonzero on failure.

Possible values of mode are _IOFBF, _IONBF, and _IOLBF.

  • _IOFBF: full buffering.
  • _IOLBF: line buffered.
  • _IONBF: no buffering.

Example

Use C setvbuf function to set buffer for stream.

#include <stdio.h>
/*from   w  ww.  j a  v  a  2s  . c  o  m*/
int main ()
{
  FILE *fp;

  fp=fopen ("myfile.txt","w");

  setvbuf ( fp , NULL , _IOFBF , 1024 );

  // File operations here

  fclose (fp);

  return 0;
}




















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h