리그캣의 개발놀이터

fflush - 스트림을 비우기 본문

프로그래밍 언어/C++

fflush - 스트림을 비우기

리그캣 2018. 2. 1. 21:19

fflush



스트림을 비웁니다


1
2
3
4
5
6
7
8
 
int fflush(
 
FILE *stream
 
);
 
 
cs



설명


fflush() 함수는 시스템이 지정된 출력 stream과 연관된 버퍼를 비우게 합니다. stream이 입력을 위해 열려있는 경우 fflush() 함수는 ungetc() 함수의 효과를 실행 취소 합니다.



이 예는 스트림 버퍼를 삭제합니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
 
int main(void)
{
   FILE *stream;
   int ch;
   unsigned int result = 0;
 
   stream = fopen("mylib/myfile", "r");
   while ((ch = getc(stream)) != EOF && isdigit(ch))
      result = result * 10 + ch - '0';
   if (ch != EOF)
      ungetc(ch,stream);
 
   fflush(stream);        /* fflush undoes the effect of ungetc function */
   printf("The result is: %d\n", result);
   if ((ch = getc(stream)) != EOF)
      printf("The character is: %c\n", ch);
}
cs


출처 : IBM



Comments