C Tutorial/stdio.h/setbuf — различия между версиями

Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
(нет различий)

Текущая версия на 10:32, 25 мая 2010

setbuf

Item Value Header file stdio.h Declaration void setbuf(FILE *stream, char *buf); Function specifies the buffer that stream will use or,

  1. Set buf to null to turn off buffering.
  2. The buffer must be BUFSIZ characters long.
  3. BUFSIZ is defined in <stdio.h>.


#include <stdio.h>
int main ()
{
  char buffer[BUFSIZ];
  FILE *fp1, *fp2;
  fp1=fopen ("test.txt","w");
  fp2=fopen ("test2.txt","a");
  setbuf ( fp1 , buffer );
  fputs ("This is sent to a buffered stream",fp1);
  fflush (fp1);
  setbuf ( fp2 , NULL );
   fputs ("This is sent to an unbuffered stream",fp2);
  fclose (fp1);
  fclose (fp2);
  return 0;
}