我有下面的代码,它应该与用户交互,了解他想要做什么。
int input;
printf("Would you like to update the name of the student?\n");
printf("Enter Y(yes) or N(no)\n");
input = getchar();
if (input == 'Y' || input == 'y') {
printf("Please enter the updated name\n");
scanf("%s", tmpSt->name);
}
printf("Would you like to update the student's ID?\n");
printf("Enter Y(yes) or N(no)\n");
input = getchar();
Run Code Online (Sandbox Code Playgroud)
但执行时它不会停止获取第一个输入。
Would you like to update the name of the student?
Enter Y(yes) or N(no)
Would you like to update the student's ID?
Enter Y(yes) or N(no)
Run Code Online (Sandbox Code Playgroud)
它应该得到名称的答案,但它直接转到 …