C Library Function - setbuf()
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
- stream -- This is a pointer to a FILE object that identifies an open stream.
- buffer -- This is the buffer allocated to the user; its length is at least BUFSIZ bytes, where BUFSIZ is a macro constant representing the array length.
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 -