Latest web development tutorials

C library functions - setbuf ()

C standard library - <stdio.h> C standard library - <stdio.h>

description

How C library functionsvoid setbuf (FILE * stream, char * buffer) should be defined flow stream buffer.This function is called once before when should the flow stream associated file is opened, and have not any input or output operations occur.

statement

Here is () statement setbuf function.

void setbuf(FILE *stream, char *buffer)

parameter

  • stream - This is a pointer to FILE pointer to an object, the object identifier FILE an open stream.
  • buffer - This buffer is assigned to the user, its length is at least BUFSIZ bytes, BUFSIZ macro is a constant representing the length of the array.

return value

This function does not return a value.

Examples

The following example demonstrates setbuf () function is used.

#include <stdio.h>

int main()
{
   char buf[BUFSIZ];

   setbuf(stdout, buf);
   puts("This is w3cschool");

   fflush(stdout);
   return(0);
}

Let's compile and run the above program, which will produce the following results. Here, at the time of the upcoming program output, send output to STDOUT, otherwise it will buffer output. You can also use the fflush () function to flush the output.

This is w3cschool

C standard library - <stdio.h> C standard library - <stdio.h>