我在这里试图做一些我觉得很容易的事情...... :-) 希望你们能帮助我。
这是为Linux Ubuntu编写的C函数......
我只需要显示一条确认消息,我希望用户按ENTER继续。
#include <stdio.h>
#include <time.h>
void setDeposit(int account, int amount)
{
printf("You have successfully transfered %d EUR to the account number %d\nPlease press ENTER to continue\n", account, amount);
getchar();
}
应用程序&#34;忽略&#34; getchar()并继续前进。
EDITED包括评论中要求的整个程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rbs-accmgr.c"
#include "rbs-graphics.c"
#include "rbs-struct.c"
//Main application function
int main()
{
//Creating the application control instance
application a = {1, 0, 0};
//Populating the customer information with the login interface information
customer c = {1234, "John", "Deer", 0};
//Clearing the terminal window
system("clear");
//Keeps the application running as long as the user doesn't hit option 9 (Quit)
while (a.status == 1)
{
//Displaying the graphic objects
displayBanner();
displayMenu();
scanf("%d",&a.selectedOption);
displayBanner();
switch(a.selectedOption)
{
//Deposit
case 1:
printf("\nHow much would you like to deposit?\n");
scanf("%d",&a.operationAmount);
setDeposit(c.account, a.operationAmount);
break;
//Wrong option
default:
a.status = 0;
break;
}
//Making sure all variables are zeroed
a.operationAmount = 0;
}
return 0;
}
我在这里做错了什么?
谢谢!
答案 0 :(得分:1)
请尝试以下方法告诉我。我认为您编写的getChar
使用了scanf
。阅读单独的while
的{{1}}可以排除这种情况。我写了char
以防你使用其他操作系统。
\r
有关此案例的详细信息,请参阅this thread。