-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');
}
이 출력 내가 얻을 수있다? 문제가있는 곳이면 누구나 볼 수 있습니까?
다음 'printf' 호출에서? : D – c00kiemon5ter
c00kie가 문제가 될 수 있습니다. '% d : % d'을'% d : % d \ n'으로 변경하면 여분의 제로가 사라지나요? – sarnold
두 번째 입력 후에'clearInput();'을 호출하십시오. – adatapost