User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdio.h:setbuf

setbuf

    void setbuf(FILE *stream, char *buffer);

Controls buffering for stream stream. For null buf, turns off buffering, otherwise equivalent to (void)setvbuf(stream, buf, _IOFBF, BUFSIZ).

setbuf is deprecated use setvbuf instead

C Sourcecode Example

/* 
 * 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;
}
  output: ./setbuf
  

content of test.txt

Buffered input for test.txt

content of test2.txt

Buffered input for test2.txt

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/setbuf.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz