Please correct the language of c.

Asked 2 years ago, Updated 2 years ago, 32 views

It's a code that I made When I debugged it, the computer was not affected by the if part and just kept running Which part is the problem...?

#include<string.h>
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
    char str1[10];
    char str2[10];
    char str3[10];

    int num1, res;
        printf("0P #1 : ");
        scanf("%s", str1);
    while (str1[0] != '0')
    {

        printf("OPER : ");
        scanf("%s", str2);
        printf("OP #2 : ");
        scanf("%s", str3);
        if (str2[0] == '@')
        {
            strcat(str1, str3);
            num1 = atoi(str1);
            res = num1 + 1;
            printf("result : %d\n", res);
        }
        else
        {
            strcat(str3, str1);
            num1 = atoi(str3);
            res = num1 - 1;
            printf("result : %d\n", res);
        }
    }

    return 0;
}

c strcat atoi

2022-09-22 15:15

1 Answers

Declare str1, str2, and str3 in the while statement, and modify it to the input code. If you want to end the while statement, try to end it when str1 comes with bye~


2022-09-22 15:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.