Second scanf is not working

前端 未结 5 1670
旧巷少年郎
旧巷少年郎 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:05

    You're getting the implicit newline you entered as the second character, i.e. st[1] is getting the value '\n'. An easy way to fix this is to include the newline in the expected format string: scanf("%c\n", &st[0]);

提交回复
热议问题