C/File/Stream Buffer

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Change stream buffering: how to setbuf

#include <stdio.h>
int main ()
{
  char buffer[256];
  FILE *file1, *file2;
  file1=fopen ("f1.txt","w");
  file2=fopen ("f2.txt","a");
  setbuf ( file1 , buffer );
  fputs ("This is sent to the buffered stream: file1",file1);
  fflush (file1);
  setbuf ( file2 , NULL );
  fputs ("This is sent to the unbuffered stream: file2",file2);
  fclose (file1);
  fclose (file2);
  return 0;
}