Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function - setbuf()

C Library Function - setbuf()

C Standard Library - <stdio.h> C Standard Library -

Description

C Library Function **void setbuf(FILE stream, char buffer) Defines how the stream stream should be buffered. This function should be called once when the file associated with the stream has been opened but before any input or output operation has occurred.

Declaration

The following is the declaration of the setbuf() function.


void setbuf(FILE *stream, char *buffer)

Parameters

Return Value

This function does not return any value.

Example

The following example demonstrates the use of the setbuf() function.


#include 

int main()
{
   char buf[BUFSIZ];

   setbuf(stdout, buf);
   puts("This is runoob");

   fflush(stdout);
   return(0);
}

Let's compile and run the above program, which will produce the following result. Here, the program sends output to STDOUT when it is about to output; otherwise it buffers the output. You can also use the fflush() function to flush the output.


This is runoob

C Standard Library - <stdio.h> C Standard Library -