DESCRIPTION
The function fflush forces a write of all buffered data for the
given output or update stream via the
stream's underlying write function. The open status of the
stream is unaffected.
If the stream argument is NULL, fflush flushes all open output
streams.
int tcflush (int filedes, int queue)
The tcflush function is used to clear the input and/or output queues
associated with the terminal file filedes. The queue argument specifies
which queue(s) to clear, and can be one of the following values
TCIFLUSH
Clear any input data received, but not yet read.
TCOFLUSH
Clear any output data written, but not yet transmitted.
TCIOFLUSH
Clear both queued input and output.
Re: fflush(stdin); <---이거 왜 gcc에서 먹통인가요???
man 페이지를 보면 이런 내용이..
DESCRIPTION
The function fflush forces a write of all buffered data for the
given output or update stream via the
stream's underlying write function. The open status of the
stream is unaffected.
If the stream argument is NULL, fflush flushes all open output
streams.
^^; stdin은 입력받는 스트림인데, fflush 해봐야 소용없겠죠?
그럼 gcc엔 입력스트림 비워버리는 함수는 따로 없나요??
그럼 gcc에선 입력스트림 비우기 위해 어떤 함수 쓰나요??
출력스트림을 비우는게 있으면
입력스트림도 비우는게 있을텐데..
char junk[80];
gets(junk);
이런방법은 말고..
Re^3: 그럼 gcc엔 입력스트림 비워버리는 함수는 따로 없나요??
gcc 가 아니라 glibc이죠..^^
int tcflush (int filedes, int queue)
The tcflush function is used to clear the input and/or output queues
associated with the terminal file filedes. The queue argument specifies
which queue(s) to clear, and can be one of the following values
TCIFLUSH
Clear any input data received, but not yet read.
TCOFLUSH
Clear any output data written, but not yet transmitted.
TCIOFLUSH
Clear both queued input and output.
Re^4: 그럼 gcc엔 입력스트림 비워버리는 함수는 따로 없나요??
제가 아직 테스트는 안해 봤는데.
여기서 버퍼를 클리어 한다는게,
그냥 버린다는 것인지? 아니면 싱크를 의미하는 것인지
모르겠네요...
ps. 전 입력 버퍼에서 바로 바로 읽어 드려야
하는 상황이라면(줄단위 입력이 아니라면)
getc를 사용하거든요
Re^4: 그럼 gcc엔 입력스트림 비워버리는 함수는 따로 없나요??
죄송합니다만..
제가 프로그램공부한지 얼마 안되서 그러는데요..
표준입력 버퍼를 비워버릴려면..
tcflush(0, TCIFLUSH);
이렇게 쓰는게 맞나요?
제가 이렇게 한번 해봤는데요..
fgets(ch, 5, stdin); tcflush(0, TCIFLUSH);
fgets(ch2, 5, stdin);
이렇게 해서 실행시켜서
12345
이렇게 치면
ch 에는 1234가 저장되구 버퍼가 비워졌으면 다시
입력 받아야 되는데..
그냥 ch2에 5가 입력 되버리더군요.
0도 해보고 1도 해보고 TCIFLUSH, TCOFLUSH, TCIOFLUSH
다 해봤는데..계속 같은 현상이..
너무 초보적인 질문 드려서 죄송합니다.
꼭좀 가르쳐 주시면 감사하겠습니다.
Re^5: 그럼 gcc엔 입력스트림 비워버리는 함수는 따로 없나요??
#include
#include
#include
int main(void)
{
char ch[5];
char ch2[5];
int read_n1;
int read_n2;
read_n1 = read(0, ch,5);
ch[read_n1-1] = '\0';
tcflush(0, TCIFLUSH);
read_n2 = read(0, ch2,5);
ch2[read_n2-1] = '\0';
printf("ch%s , ch2%s",ch,ch2);
}
이렇게 하면 잘 돼는군요.^^
stdio.h 함수는 안되는것 같습니다. 내부적으로 버퍼를 이용하거든요..
그거 비우는거는..찾아볼께요..
Re^6: 그럼 gcc엔 입력스트림 비워버리는 함수는 따로 없나요??
#include
#include
#include
#include
int main(void)
{
char ch[5];
char ch2[5];
int read_n1;
int read_n2;
fgets(ch, 5, stdin);
__fpurge (stdin); // key point
fgets(ch2, 5, stdin);
printf("ch%s , ch2%s",ch,ch2);
}
이렇게 하니 되네요.
아 일해야 하는데...
저 짤리겠어요.
후후...좋은 하루.~~~
임동현님 감사합니다^^
신경써 주셔서 너무 감사합니다.
^^
메일로 가면 귀찮으실까바 그냥 제글에 리플 달았습니다.
(근데 저 헤더파일이랑 함수 man 해보니깐 안나오네요...)
기럼 안시표준으론 입력스트림 지우는 함수 없나요??
움 stdio_ext.h 이란 헤더가 없다고 나와서
아직 못해보고 있는데..
__fpurge() 라는 함수는 아무래도 안시표준하고는 거리가
있는 함수같은지라..
안시표준 함수로..
입력스트림에 아직 남아있는 불필요한 입력을
지우는 함수는 정녕 없나요?
댓글 달기