In this program, I tried to write my simple calculator equation firstly. Then, I will obtain my result. When I write this program, I got two warnings:
- usertext use uninitialized memory where
printf("%c", usertxt[i]);
scanf_s
: not enough arguments passed to format string wherescanf_s("%c", &myoperator);
#include<stdio.h>
#define SIZE 50
int i = 0;
int main() {
char usertxt[SIZE], myoperator;
printf("addition='+',subtraction='-',multiplication='*',division='/'
");
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);
if (myoperator == '') {
break;
switch (myoperator) {
case '+':printf("Addition operation
");
printf(" Enter your number: ");
scanf_s("%d", &myarray[i]);
usertxt[i] = printf("%d%c", myarray[i], myoperator);
break;
case '-':
printf("Subtraction operation
");
printf("Enter your numbers: ");
scanf_s("%d", &myarray[i]);
usertxt[i] = printf("%d%c", myarray[i], myoperator);
break;
case '*':
printf("Multiplication operation
");
printf("Enter your numbers: ");
scanf_s("%d", &myarray[i]);
usertxt[i] = printf("%d%c", myarray[i], myoperator);
break;
case '/':
printf("Division operation
");
printf("Enter your numbers: ");
scanf_s("%d", &myarray[i]);
usertxt[i] = printf("%d%c", myarray[i], myoperator);
break;
};
}
}
for (int m = 0; m < i; m++) {
printf("%c", usertxt[i]);
}
question from:https://stackoverflow.com/questions/66055332/how-can-i-correct-this-error-in-my-c-program