[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


setbuf

Change the buffer size of a stream.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stdio.h>
void setbuf(FILE *stream, char *buf);
Parameters:

Parameters for this facility are:

stream  
FILE *  
A pointer to a FILE stream  
buf  
char *  
A buffer for input or output  

Remarks:

The setbuf() function allows the programmer to set the buffer size for stream. It should be called after stream is opened, but before it is read from or written to.

The function makes the array pointed to by buf the buffer used by stream. The buf argument can either be a null pointer or point to an array of size BUFSIZ, defined in stdio.h.

If buf is a null pointer, the stream becomes unbuffered.

See Also:

"setvbuf"

"malloc"

Example of setbuf() usage.:
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	FILE *f;
	char name[80];

	// get a filename from the user
	printf("Enter the name of the file to write to.\n");
	gets(name);

	// create a new file for output
	if ( (f = fopen(name, "w")) == NULL) {
		printf("Can't open file %s.\n", name);
		exit(1);
	}

	setbuf(f, NULL);		// turn off buffering

	// this text is sent directly to the file without
	// buffering
	fprintf(f, "Buffering is now off\n");
	fprintf(f, "for this file.\n");

	// close the file
	fclose(f);

	return 0;
}

Output:
Enter the name of the file to write to.
bufftest


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000