为什么要跳过 getchar()?

Why is getchar() being skipped?

下面是我正在处理的代码。输出是这样的:

Enter Nums: 20 4
OP: Which option was that?

op = getchar(); 部分被完全忽略。为什么?
我正在使用 gcc 4.6.2 MinGW。


#include <stdio.h>
int add(int num1, int num2) {
    return num1 + num2;
}

int subs(int num1, int num2) {
    return num1 - num2;
}

int mul(int num1, int num2) {
    return num1 * num2;
}

float div(int num1, int num2) {
    return (float)num1 / num2;
}

int main(int argc, char* argv[]) {
    int num1, num2;
    char op;
    fprintf(stdout,"Enter Nums: ");
    scanf("%d %d",&num1,&num2);
    fprintf(stdout, "OP: ");
    op = getchar();
    switch(op) {
    case '+':
        printf("%d",add(num1, num2));
        break;
    case '-':
        printf("%d", subs(num1,num2));
        break;
    case '*':
        printf("%d",mul(num1,num2));
        break;
    case '/':
        printf("%f",div(num1, num2));
        break;
    default:
        printf("Which option was that?\n");
    }
    return 0;
}
scanf("%d %d",&num1,&num2);

此输入后有换行符,请忽略

scanf("%d %d%*c",&num1,&num2);

while((c=getchar()) != '\n') && c != EOF);

否则换行符会被 getchar()