Change the buffer size of a stream.
Compatibility:This function is compatible with the following targets:
|
|
#include <stdio.h>
void setbuf(FILE *stream, char *buf);Parameters:
Parameters for this facility are:
If buf is a null pointer, the stream becomes unbuffered.
#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