scanf function seems to be skipped in c

后端 未结 5 464
星月不相逢
星月不相逢 2020-12-06 03:43

I am new to c language, and I tried this code below, but it seems scanf has been skipped, when I run this code, it only asked me enter name and age and skipped the lines bel

5条回答
  •  情话喂你
    2020-12-06 04:16

    You can do the following for all scanfs.

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

    And then enter the values one by one separating them by newlines (press Enter).

    This helped me too when I had the same problem.

    scanf("%c*",&smth);
    

    That makes scanf skip any other characters that a user might input, including newlines.


    Note: use appropriate format strings for each type (%s for strings, %d for integers, etc).

提交回复
热议问题