while (getchar () != '\n' );

前端 未结 6 532
囚心锁ツ
囚心锁ツ 2021-01-03 17:08

I have the following for loop, I am prompting the user to enter a 4 digit pin and hit enter. Can someone explain to me what the while loop is really doing because I don\'t f

6条回答
  •  旧时难觅i
    2021-01-03 18:14

    The next line is discarding the possible extra chars that the user may have inputted, and also the linefeed char that the user had to input.

    So other scanf/getchar methods further in the code are not polluted by this spurious input.

提交回复
热议问题