C语言-常用函数处理

1.使用fgets

#define SLEN 50

char str[SLEN];

fgets(str, SLEN, stdin);

i = 0;
while (str[i] != '\n' && str[i] != '\0')
    i++

if (str[i] == '\n')
    str[i] = '\0'
else
    while (getchar() != '\n')
        continue;

2.使用getchar()过滤掉输入缓存中的剩余部分

void eatline(void) {
    while (getchar() != '\n')
        continue;
}

3.

  

posted on 2015-07-01 10:03  John_ABC  阅读(351)  评论(0编辑  收藏  举报

导航