Change the buffering scheme for a stream.
Compatibility:This function is compatible with the following targets:
|
|
#include <stdio.h>
int setvbuf(FILE *stream, char *buf, int mode,  
size_t size);
Parameters for this facility are:
If buf is a null pointer, then the operating system creates its own buffer of size bytes.
_IOFBF specifies that stream be buffered.
_IOLBF specifies that stream be line buffered.
_IONBF specifies that stream be unbuffered
setvbuf() returns zero if it is successful and returns a nonzero value if it fails.
See Also:
Example of setvbuf() 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);
}
setvbuf(f, NULL, _IOLBF, 0); // line buffering
fprintf(f, "This file is now\n");
fprintf(f, "line buffered.\n");
// close the file
fclose(f);
return 0;
}
Output:
Enter the name of the file to write to.
buffy
[ 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