Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

How can I overcome from this error in my C program?

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

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...