C setbuf() function
C library function - setbuf()
The setbuf() function controls buffering for the specified stream if the operating system supports user-defined buffers. The stream pointer must refer to an open file before any I/O or repositioning has been done.
Syntax:
void setbuf(FILE *stream, char *buffer)
setbuf() Parameters:
Name | Description | Required /Optional |
---|---|---|
stream | Identifies an address for a file descriptor, which is an area of memory associated with an input or output stream. | Required |
buffer | The system uses the buffer, which you specify, for input/output buffering instead of the default system-allocated buffer for the given stream. | Required |
Return value from setbuf()
- This function does not return any value.
Example: setbuf() function
The following example opens the file test.txt for writing. As a result, it calls the setbuf() function in order to create a buffer of length BUFSIZ. Strings are written to the stream using the buffer buf, which contains the string before it is flushed to the file.
Output:
String is found in buffer now. C Programming.
C Programming Code Editor:
Previous C Programming: C rewind()
Next C Programming: C setvbuf()
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics