C语言函数—setvect

函数名

setvbuf

功 能

把缓冲区与流相关

用 法

int setvbuf(FILE *stream, char *buf, int type, unsigned size);

程序例

#include <stdio.h> 

int main(void) 
{ 
   FILE *input, *output; 
   char bufr[512]; 

   input = fopen("file.in", "r+b"); 
   output = fopen("file.out", "w"); 

   /* set up input stream for minimal disk access, 
      using our own character buffer */ 
   if (setvbuf(input, bufr, _IOFBF, 512) != 0) 
      printf("failed to set up buffer for input filen"); 
   else 
      printf("buffer set up for input filen"); 

   /* set up output stream for line buffering using space that 
      will be obtained through an indirect call to malloc */ 
   if (setvbuf(output, NULL, _IOLBF, 132) != 0) 
      printf("failed to set up buffer for output filen"); 
   else 
      printf("buffer set up for output filen"); 

   /* perform file I/O here */ 

   /* close files */ 
   fclose(input); 
   fclose(output); 
   return 0; 
} 
  
  
  

如果引用本站的原创文章,请注明原文链接:,本站保留追究责任的权利!
评论已关闭。