2012-06-29 3 views
-1

나는이 다음 코드 :이 이상한 출력의 원인은 무엇입니까?

Where is the piece you want to move?(rc):51 
5:1 
Where is the space you want to move to?(rc):40 
4:00 

뭐죠 추가 0 최대 :

void doPlayerMove(void) 
{ 
    bool moved = false; 

    while (!moved) 
    { 
     printf("\nWhere is the piece you want to move?(rc):"); 
     int r = getchar() - '0';// gets the row number 
     int c = getchar() - '0';// gets the column number 

     printf("%d:%d", r, c);// prints the chosen row/column 

     clearInput(); 
     printf("\nWhere is the space you want to move to?(rc):"); 
     int r2 = getchar() - '0'; 
     int c2 = getchar() - '0'; 

     printf("%d:%d", r2, c2); 

     ... 
    } 
} 

void clearInput(void) 
{ 
    while(getchar() != '\n'); 
} 

이 출력 내가 얻을 수있다? 문제가있는 곳이면 누구나 볼 수 있습니까?

+1

다음 'printf' 호출에서? : D – c00kiemon5ter

+1

c00kie가 문제가 될 수 있습니다. '% d : % d'을'% d : % d \ n'으로 변경하면 여분의 제로가 사라지나요? – sarnold

+0

두 번째 입력 후에'clearInput();'을 호출하십시오. – adatapost

답변

0

영업 이익은 주석에서 말하기를 :

문제가 해결, 그것은 내가 에서 호출 된 일부 기능의 일부 출력이었다 허위 경보에 대한 ... 죄송합니다!

관련 문제