[C] 把缓冲区与流相关 →→→→→进入此内容的聊天室

来自 , 2019-06-10, 写在 C, 查看 150 次.
URL http://www.code666.cn/view/27344841
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5.    FILE *input, *output;
  6.    char bufr[512];
  7.  
  8.    input = fopen("file.in", "r+b");
  9.    output = fopen("file.out", "w");
  10.  
  11.    /* set up input stream for minimal disk access,
  12.       using our own character buffer */
  13.    if (setvbuf(input, bufr, _IOFBF, 512) != 0)
  14.       printf("failed to set up buffer for input file\n");
  15.    else
  16.       printf("buffer set up for input file\n");
  17.  
  18.    /* set up output stream for line buffering using space that
  19.       will be obtained through an indirect call to malloc */
  20.    if (setvbuf(output, NULL, _IOLBF, 132) != 0)
  21.       printf("failed to set up buffer for output file\n");
  22.    else
  23.       printf("buffer set up for output file\n");
  24.  
  25.    /* perform file I/O here */
  26.  
  27.    /* close files */
  28.    fclose(input);
  29.    fclose(output);
  30.    return 0;
  31. }

回复 "把缓冲区与流相关"

这儿你可以回复上面这条便签

captcha