When I write simple calculator program, firstly I want to obtain simple calculator equation then with usertxt I can get compiler to write this process again. Although I didn't get continuing process, I wanted to forward step by step. I encountered with two errors.
I get 2 errors at line 12 scanf_s("%c", &myoperator[i]);
:
'scanf_s': not enough arguments passed to format string
conversion token corresponding to 'scanf_s' element, missing integer parameter.
Also, I want to determine that error is not relation with scanf_s
. I have already used visual studio. I couldn't find how I can correct this issue. Thanks in advance.
#include <stdio.h>
#define SIZE 50
int i = 0;
int main() {
char usertxt[SIZE], myoperator[SIZE];
printf("addition='+',subtraction='-',multiplication='*',division='/'
");
usertxt[0] = 0;
int x, myarray[SIZE];
printf("How many numbers should be entered? ");
scanf_s("%d", &x);
for (i = 0; i < x; i++) {
scanf_s("%c", &myoperator[i]);
if (myoperator[i] == '') {
break;
switch (myoperator[i]) {
case '+':
printf("Addition operation
");
printf(" Enter your number: ");
scanf_s("%d", &myarray[i]);
usertxt[i] = printf("%d%c", myarray[i], myoperator[i]);
break;
case '-':
printf("Subtraction operation
");
printf("Enter your numbers: ");
scanf_s("%d", &myarray[i]);
usertxt[i] = printf("%d%c", myarray[i], myoperator[i]);
break;
case '*':
printf("Multiplication operation
");
printf("Enter your numbers: ");
scanf_s("%d", &myarray[i]);
usertxt[i] = printf("%d%c", myarray[i], myoperator[i]);
break;
case '/':
printf("Division operation
");
printf("Enter your numbers: ");
scanf_s("%d", &myarray[i]);
usertxt[i] = printf("%d%c", myarray[i], myoperator[i]);
break;
};
}
}
for (int m = 0; m < i; m++) {
printf("%c", usertxt[m]);
}
}
question from:
https://stackoverflow.com/questions/66060067/how-can-i-overcome-from-this-error-in-my-c-program 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…