User Tools

Site Tools


c:stdio.h:setbuf

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:stdio.h:setbuf [2013/01/22 22:02] (current)
Line 1: Line 1:
 +{{keywords>wiki library source code example reference}}
 +====== setbuf ======
 +<code c>
 +    void setbuf(FILE *stream, char *buffer);
 +</code>
 +Controls buffering for stream stream. For null buf, turns off buffering, otherwise equivalent to (void)setvbuf(stream, buf, _IOFBF, BUFSIZ).
 +
 +setbuf is deprecated use [[c:stdio.h:setvbuf|]] instead
 +===== C Sourcecode Example =====
 +<code c>
 +/* 
 + * setbuf example code
 + * http://code-reference.com/c/stdio.h/setbuf 
 + */
 +
 +#include <stdio.h> /* including standard library */
 +//#include <windows.h> /* uncomment this for Windows */
 +
 + 
 +int main( void )
 +{
 +  FILE *stream = fopen("test.txt", "w");
 +  FILE *stream2 = fopen("test2.txt","w");
 + 
 +  char buffer[100];
 +  char buffer2[BUFSIZ];  
 +  
 +  setbuf(stream, buffer);
 +  fputs("Buffered input for test.txt", stream);
 +  fflush(stream);
 +  fclose(stream);
 +
 +  setbuf(stream2, buffer2);
 +  fputs("Buffered input for test2.txt", stream2);
 +  fflush(stream2);
 +  fclose(stream2);
 +
 +  return 0;
 +}
 +</code>
 +
 +
 +    output: ./setbuf
 +    
 +==== content of test.txt ===
 +<code c>
 +Buffered input for test.txt
 +</code>
 +
 +==== content of test2.txt ===
 +<code c>
 +Buffered input for test2.txt
 +</code>
 +
 +
 +
  
advertising
c/stdio.h/setbuf.txt · Last modified: 2013/01/22 22:02 (external edit)

Impressum Datenschutz