Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

  1. usertext use uninitialized memory where printf("%c", usertxt[i]);
  2. scanf_s: not enough arguments passed to format string where scanf_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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
131 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try using scanf instead of scanf_S


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...