从 c 中的键盘获取字符时出现多字符警告

Multi-character warning while get a char from keyboard in c

根据键盘输入的操作,想用switch结构做5个操作,报错。我还尝试了 getchar 和 putchar 函数...

    int main()
    {
        char proc;
        int firstNum,secondNum,result;
        printf("* Multiplication\n/ Division\n+ Add \n- Minus\n%c Mode", '%');
        printf("\nEnter the first number: ");
        scanf("%d",&firstNum);
        printf("\nEnter the second number: ");
        scanf("%d",&secondNum);
        printf("\nEnter the process: ");
        scanf("%c",&proc);

        switch(proc) {
        case '*':
            result=firstNum*secondNum;
            printf ('%d',result);
            break;
        case '/':
            result=firstNum/secondNum;
            printf ('%d',result);
            break;
        case '+':
            result=firstNum+secondNum;
            printf ('%d',result);
            break;
        case '-':
            result=firstNum-secondNum;
            printf ('%d',result);
            break;
        case '%':
            result=firstNum%secondNum;
            printf ('%d',result);


    break;
    default:
        printf('Warning!');
        break;
}

warning: multi-character character constant [-Wmultichar]

warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]

初学者使用

scanf(" %c",&proc);
       ^^^

(见字符&前的空格)而不是

scanf("%c",&proc);

并在这样的语句中使用双引号指定字符串文字

printf ( "%d",result);
         ^^^^

或这个

 printf("Warning!");
       ^^^      ^^^ 

而且你忘记了程序末尾的右大括号。