C library functions -setbuf()
C Standard Library - <stdio.h>
Description
C Library Functionsvoid setbuf(FILE *stream, char *buffer)Defines how the stream should be buffered. This function should be called once when the file associated with the stream is opened, before any input or output operations have occurred.
Declaration
Below is the declaration of the setbuf() function.
void setbuf(FILE *stream, char *buffer)
Parameter
- stream-- This is a pointer to a FILE object that identifies an open stream.
- buffer-- This is the user-allocated buffer, whose length is at least BUFSIZ bytes. BUFSIZ is a macro constant representing the length of the array.
Return Value
This function returns no value.
Example
The following example demonstrates the usage of the setbuf() function.
#include <stdio.h>
int main()
{
char buf[BUFSIZ];
setbuf(stdout, buf);
puts("This is example");
fflush(stdout);
return(0);
}
Let us compile and run the above program, which will produce the following results. 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 exampleother extensions