C语言scanf_s()多个值时出错

#include <stdio.h>#include <stdlib.h>int main(void) { double number1; double number2; char operation = 0 ; printf("\nEnter the calculation\n"); scanf_s("%lf %c %lf", &number1, &operation, &number2); switch (operation) { case '+': printf("= %lf\n", number1 + number2); break; case '-': printf("= %lf\n", number1 - number2); break; case '*': printf("= %lf\n", number1 * number2); break; case '/': if (number2 == 0) { printf("\ncant be zero\n"); } else { printf("= %lf\n", number1 / number2); } break; case'%': if ((long)number2 == 0) { printf("cant be zero"); } else { printf("%ld", (long)number1 % (long)number2); } break; default: printf("illegal"); break; } system("pause"); return 0;}程序目的是输入数字和运算符得到结果出问题的是scanf_s("%lf %c %lf", &number1, &operation, &number2);这一行如果直接运行会卡住,然后跳出图示的问题但是如果将此行语句修改为scanf_s("%lf %lf %c", &number1, &number2, &operation);就可以正常运行了。请教是什么问题

把%lf %c %lf中间的空格去掉,改为%lf%c%lf追问

我改了之后输出一直是illegal,相当于operation不是+-*/

追答

把你写的代码传上来看。

追问

用的是vs2017

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-01-02
放中间会使第二个变量读取\n,,,
相似回答