Pointer to the `FILE` stream whose buffering mode is to be set.
2nd Parameter Type : char *
String pointer (array of characters)
2nd Parameter
Pointer to a user-provided buffer to be used for stream I/O. If `buffer` is `NULL`, the function allocates an internal buffer if necessary.
3rd Parameter Type : int
Integer type (typically 4 bytes, -2,147,483,648 to 2,147,483,647)
3rd Parameter
The buffering mode to set for the stream: `_IOFBF` (full buffering), `_IOLBF` (line buffering), or `_IONBF` (no buffering).
4th Parameter Type : size_t
Platform-specific unsigned type for array indices and memory sizes.
4th Parameter
The size of the buffer in bytes, if `buffer` is not `NULL`.
Read more about parameters of setvbuf in parameters section
The setvbuffunction in C language Sets a specific buffer and buffering mode for the given stream.
The setvbuf function allows you to specify the buffering mode and buffer size for a stream. It can be used to optimize I/O operations by controlling how data is buffered before being read from or written to a device.
The setvbuffunction takes 4
parameters:
•
FILE * `stream`: Pointer to the `FILE` stream whose buffering mode is to be set.
•
char * `buffer`: Pointer to a user-provided buffer to be used for stream I/O. If `buffer` is `NULL`, the function allocates an internal buffer if necessary.
•
int `mode`: The buffering mode to set for the stream: `_IOFBF` (full buffering), `_IOLBF` (line buffering), or `_IONBF` (no buffering).
•
size_t `size`: The size of the buffer in bytes, if `buffer` is not `NULL`.
Sets the buffering mode and buffer size for the specified `FILE` stream. The mode can be full buffering (`_IOFBF`), line buffering (`_IOLBF`), or no buffering (`_IONBF`). If `buffer` is `NULL`, an internal buffer is used. Returns `0` on success or a nonzero value on failure.
The setvbuf function return value :
Returns 0 on success, or a non-zero value if an invalid value is given for mode or if the request cannot be honored
Output
This example sets a custom fully buffered buffer for a file stream using setvbuf.