강의

멘토링

커뮤니티

Inflearn Community Q&A

jdna10095878's profile image
jdna10095878

asked

Learn C Programming by Following Along with Hong Jeong-mo

8.5 Inputting mixed numbers and letters

while(getchars() != '\n')continue;

Written on

·

267

0

scanf("%c %d %d", c, rows, cols)

while(getchars() != '\n')continue;

에서 의문이 드는 점은

scanf로 입력을 받고 while문 안에있는 putchar에서 입력을 한번 더 받아야 하는거 아닌가요?

c

Answer 1

0

한 번 입력받을 경우 필요하지 않습니다.

while(getchar() != '\n')continue; 는

scanf로 입력받은 버퍼를 끝까지 비우기 위해 (공백문자까지 처리하기 위해)

사용하는 건데 while문은 입력받은 '\n'을 만날때까지 getchar() 함수를 실행하기 때문에

입력받은 내용들을 전부 처리할 수 있습니다.

jdna10095878's profile image
jdna10095878

asked

Ask a question