while (getchar () != '\n' );
问题 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 fully understand it. //user input for pin for(i = 0; i < PIN_LENGTH; i++) { printf("Enter digit %d of your PIN: ", i); user_pin[i] = getchar(); while (getchar() != '\n'); //what is this line doing?? } 回答1: When you give input to the program, then you end it with the Enter key. This key is sent to your program as a newline.