What is the problem with the scanf_s
call in my code? (I can't get the value into num2
and the command is ending before it reaches the end.)
I don't have this problem when I try to do this:
scanf_s("%c", &op);
scanf_s("%d%d", &num1,&num2);
The original code:
#include<stdio.h>
void main()
{
int num1, num2, res, opok=1;
char op;
printf("please insert your experession:\n");
scanf_s("%d%c%d", &num1, &op, &num2);
switch (op)
{
case '+':
res = num1 + num2;
break;
case '-':
res = num1 - num2;
break;
case '*':
res = num1 * num2;
break;
default:
opok = 0;
break;
}
if (opok == 1)
{
printf_s("%d\n", res);
}
else
{
printf_s("error\n");
}
}