2014-10-08 3 views
0

나는 여기에 열심히 노력하고 있습니다. 나는 쉽게 할 수있을 것이라고 생각했습니다. :-) 여러분이 저를 도울 수 있기를 바랍니다. Enter 키를 눌러 계속 진행하십시오. (Linux & C)

이 리눅스 우분투 용으로 작성된 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(); 

    } 

응용 프로그램은 getchar()을 "무시"하고 계속 이동합니다.

#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; 

} 

내가 잘못 여기서 뭐하는 거지 :

은 코멘트 요청에 따라 전체 프로그램을 포함

수정 됨?

감사합니다.

+3

당신이 얻고있는 오류 또는 당신이 직면 한 문제는 무엇입니까 ?? – Haris

+0

죄송합니다. 나는 그 질문을 갱신했다. –

+7

저에게 맞는 작품 -이 현상을 일으키는 추가 코드가 있어야합니다. 이전에 추가 입력을 읽고 있습니까 (예 :'scanf()?)? –

답변

1

아래 내용을 시도해주세요. 나는 당신이 쓴 scanf에 의해 getChar이 사용 된 것 같아요. while을 별도로 읽으면 그 것을 배제 할 수 있습니다. 다른 운영 체제를 사용하는 경우를 대비하여 \r이라고 적었습니다.

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); 

    char myChar = 0; 
    while (myChar != '\n' && myChar != '\r') { 
     myChar = getchar(); 
    } 
} 

자세한 내용은 this thread에서 확인할 수 있습니다.

+0

절대적으로 좋습니다. 감사! –

+1

그것이 기뻤다는 것을 알았습니다. –

관련 문제