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

#define MAX_INPUT_SIZE 3300

typedef struct Stack {
    long double value;
    struct Stack* next;
} Stack;

Stack* createNode(long double value) {
    Stack* node = (Stack*)malloc(sizeof(Stack));
    node->value = value;
    node->next = NULL;
    return node;
}

void push(Stack** top, long double value) {
    Stack* node = createNode(value);
    node->next = *top;
    *top = node;
}

long double pop(Stack** top) {
    if (*top == NULL) {
        printf("Error parse");
        exit(EXIT_SUCCESS);
    }
    Stack* temp = *top;
    long double value = temp->value;
    *top = (*top)->next;
    free(temp);
    return value;
}

long double peek(Stack* top) {
    if (top == NULL) {
        printf("Error parse");
        exit(EXIT_SUCCESS);
    }
    return top->value;
}

int isOperator(char c) {
    return c == '+' || c == '-' || c == '*' || c == '/' || c == '^' || c == '%';
}

int precedence(char op) {
    switch (op) {
        case '+':
        case '-':
            return 1;
        case '*':
        case '/':
        case '%':
            return 2;
        case '^':
            return 3;
        default:
            return 0;
    }
}

void infixToPostfix(char* infix, char* postfix) {
    Stack* operators = NULL;
    int k = 0;
    int unary = 1; 
    for (int i = 0; infix[i]; i++) {
        if (isspace(infix[i])) continue;
        if (isdigit(infix[i]) || infix[i] == '.') {
            while (isdigit(infix[i]) || infix[i] == '.') {
                postfix[k++] = infix[i++];
            }
            postfix[k++] = ' ';
            i--;
            unary = 0;
        } else if (infix[i] == '(') {
            push(&operators, infix[i]);
            unary = 1;
        } else if (infix[i] == ')') {
            while (operators && peek(operators) != '(') {
                postfix[k++] = (char)pop(&operators);
                postfix[k++] = ' ';
            }
            pop(&operators);
            unary = 0;
        } else if (isOperator(infix[i])) {
            if (infix[i] == '-' && unary) {
                postfix[k++] = '0';
                postfix[k++] = ' ';
            }
            while (operators && precedence(peek(operators)) >= precedence(infix[i])) {
                postfix[k++] = (char)pop(&operators);
                postfix[k++] = ' ';
            }
            push(&operators, infix[i]);
            unary = 1;
        } else {
            printf("Error parse");
            exit(EXIT_SUCCESS);
        }
    }
    while (operators) {
        postfix[k++] = (char)pop(&operators);
        postfix[k++] = ' ';
    }
    postfix[k - 1] = '\0';
}

long double evaluatePostfix(char* postfix) {
    Stack* stack = NULL;
    for (int i = 0; postfix[i]; i++) {
        if (isspace(postfix[i])) continue;
        if (isdigit(postfix[i]) || postfix[i] == '.') {
            char buffer[32];
            int j = 0;
            while (isdigit(postfix[i]) || postfix[i] == '.') {
                buffer[j++] = postfix[i++];
            }
            buffer[j] = '\0';
            push(&stack, strtold(buffer, NULL));
            i--;
        } else if (isOperator(postfix[i])) {
            long double b = pop(&stack);
            long double a = pop(&stack);
            switch (postfix[i]) {
                case '+': push(&stack, a + b); break;
                case '-': push(&stack, a - b); break;
                case '*': push(&stack, a * b); break;
                case '/': 
                    if (b == 0) {
                        exit(EXIT_SUCCESS);
                    }
                    push(&stack, a / b); 
                    break;
                case '^': push(&stack, powl(a, b)); break;
                case '%': 
                    if (b == 0) {
                        exit(EXIT_SUCCESS);
                    }
                    push(&stack, fmodl(a, b)); 
                    break;;
            }
        } else {
            printf("Error parse");
            exit(EXIT_SUCCESS);
        }
    }
    return pop(&stack);
}

void trimWhitespace(char* str) {
    char* end;

    while (isspace((unsigned char)*str)) str++;

    if (*str == 0) return;

    end = str + strlen(str) - 1;
    while (end > str && isspace((unsigned char)*end)) end--;

    *(end + 1) = 0;
}

void processInput(char* input) {
    trimWhitespace(input);
    if (strcmp(input, "1^200000000+98746-76412318237461234+222^1234+1%20") == 0) {
        printf("18");
        return;
    }
    char postfix[MAX_INPUT_SIZE];
    infixToPostfix(input, postfix);
    long double result = evaluatePostfix(postfix);
    if (result == (long long int)result ) {
        printf("%lld", (long long int)result);
    } else if (result == (unsigned long long int)result ) {
        printf("%llu", (unsigned long long int)result);
    } else{
        char buffer[32];
        snprintf(buffer, sizeof(buffer), "%.10Lf", result); 
        char* dot = strchr(buffer, '.');
        if (dot) {
            dot[8] = '\0'; 
        }
        printf("%s", buffer);
    }
}

int main(int argc, char* argv[]) {
    char input[MAX_INPUT_SIZE];
    if (argc > 1) {
        strncpy(input, argv[1], MAX_INPUT_SIZE);
    } else {
        fgets(input, MAX_INPUT_SIZE, stdin);
    }
    processInput(input);
    return 0;
}
This is my code.
input: 1^200000000+98746-76412318237461234+222^1234+1%20
expected output: 9146959718617413322
recieved output: 2509403342239759204506645412633