Chapter Contents

Previous

Next
setbuf

setbuf



Change Stream Buffering

Portability: ISO/ANSI C conforming, UNIX compatible, POSIX.1 conforming


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <stdio.h>

void setbuf(FILE *stream, char *buf);


DESCRIPTION

setbuf controls buffering for the specified stream on operating systems that support user-defined buffers. setbuf is similar to the setvbuf function. If buf is not NULL , then the values _IOFBF and BUFSIZE are used for setvbuf 's mode and size arguments. If buf is NULL , then the value _IONBF is used for setvbuf 's mode argument.

For FILE pointers that reference HFS files or sockets, you can use setbuf to change the buffering mode or location. If you do not use setbuf , the default buffer size for HFS files and sockets is 1008 bytes. setbuf has no effect for any other kind of file. A call to setbuf is permitted only as the first operation following the opening of a file.


RETURN VALUE

setbuf has no return value.


EXAMPLE

#include <stdio.h>

main()
{
   char input[32];

   setbuf(stdout, NULL); /* Try to prevent buffering of stdout. */
   printf("Please enter your first name:");
   fflush(stdout);       /* Try to force output to terminal.    */
   gets(input);
   printf("Thanks %s. It's been a pleasure.\n",input);
}


RELATED FUNCTIONS

setvbuf


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.