Mega Code Archive

 
Categories / C / Code Snippets
 

Specifies the buffer that stream will use

//Header file: #include <stdio.h> //Declaration: void setbuf(FILE *stream, char *buf); #include <stdio.h> int main () { char buffer[BUFSIZ]; FILE *filep1, *filep2; filep1=fopen ("testfile.txt","w"); filep2=fopen ("testfile2.txt","a"); setbuf ( filep1 , buffer ); fputs ("This is sent to a buffered stream",filep1); fflush (filep1); setbuf ( filep2 , NULL ); fputs ("This is sent to an unbuffered stream",filep2); //Set buf to null to turn off buffering. //The buffer must be BUFSIZ characters long. //BUFSIZ is defined in <stdio.h>. fclose (filep1); fclose (filep2); return 0; }