Reading a single character in C

前端 未结 5 592
攒了一身酷
攒了一身酷 2020-11-29 09:27

I\'m trying to read a character from the console (inside a while loop). But it reads more than once.

Input:

a

Output:



        
5条回答
  •  無奈伤痛
    2020-11-29 10:04

    To read just one char, use getchar instead:

    int c = getchar();
    if (c != EOF)
      printf("%c\n", c);
    

提交回复
热议问题