Second scanf is not working

前端 未结 5 1663
旧巷少年郎
旧巷少年郎 2020-12-06 19:36

i am having trouble with this c language code:

 char st[2];

 printf(\"enter first value:\");
 scanf(\"%c\", &st[0]);

 printf(\"enter second value:\");
         


        
5条回答
  •  抹茶落季
    2020-12-06 20:01

    use fflush(stdin); function before the second scanf();. It will flush the ENTER key generated after first scanf();. Actually, your second scanf() is taking the ENTER as its input and since scanf terminates after getting an ENTER, it is not taking anything else by your side.

提交回复
热议问题