Standard Library Functions in C

adplus-dvertising
setbuf() Function
Previous Home Next

Description

The C library function , The setbuf( ) function is used either to specify the buffer that stream will use or, if called with buffer set to null, to turn off buffering. If a programmer-defined buffer is to be specified, it must be BUFSIZ characters long. BUFSIZ is defined in .

Declaration


Following is the declaration for setbuf() function.

void setbuf(FILE *stream, char *buffer)

Parameters

stream - The stream pointer must refer to an open file and the setbuf function must be the first operation on the stream.

buffer - This is the user allocated buffer. This should have a length of at least BUFSIZ bytes, which is a macro constant to be used as the length of this array.

Return Value

The setbuf( ) function returns no value.

Example

#include <stdio.h>

int main(void)
{
    char buf[BUFSIZ];
    setbuf(stdin, buf);
    printf("Hello, world!\n");
    return 0;
}

Output

Hello, world!
Previous Home Next