造成这种奇怪输出的原因是什么?

时间:2012-06-29 02:09:41

标签: c

我有以下代码:

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

这是我得到的输出:

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?有没有人知道问题出在哪里?

1 个答案:

答案 0 :(得分:0)

正如OP在评论中所说:

  

问题解决了,它是我调用的某些函数的一些输出   对......误报了抱歉!