Reading a single character in C

前端 未结 5 598
攒了一身酷
攒了一身酷 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:14

    in scanf("%c",&in); you could add after %c a newline character \n in order to absorb the extra characters

    scanf("%c\n",&in);
    

提交回复
热议问题