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.

  

相关文章:

  • 2021-11-26
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2021-09-12
  • 2022-12-23
  • 2022-02-20
  • 2022-12-23
相关资源
相似解决方案