2011-12-16 3 views

답변

3

fgets, 다음 '\n'

char buf[SOME_VALUE]; 
size_t blen; 

if (fgets(buf, sizeof buf, stdin) == NULL) /* deal with error */; 
blen = strlen(buf); 
if (blen == 0) /* your system is strange! */; 
if (buf[blen - 1] == '\n') buf[--blen] = 0; 
else /* fgets "returned" an incomplete line */; 
-1
char ch; 
ch = getchar(); 
while(ch != '\n') 
    ch = getchar(); 
관련 문제