Easy Tutorial
❮ C Function Wcstombs C Function Isalnum ❯

C Library Function - setbuf()

C Standard Library - <stdio.h>

Description

The C library function void setbuf(FILE *stream, char *buffer) defines how the stream should be buffered. This function should be called once for the stream associated with a file that has been opened and before any input or output operations have occurred.

Declaration

Here is the declaration for 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 <stdio.h>

int main()
{
   char buf[BUFSIZ];

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

   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 just before it is about to exit, otherwise, it buffers the output. You can also use the fflush() function to flush the output.

This is tutorialpro

C Standard Library - <stdio.h>

❮ C Function Wcstombs C Function Isalnum ❯