I have encountered a problem in having an Error c>= -1 && c<= 225

-1

This function is expressed in final representation, with spaces before and after each operand, and before and after each expression representing the expression tree operator, except at the beginning and end of the look. The function builds and returns a pointer to the root of the tree.

node* create_expr_tree(char *postfix)
{
    stack* s = CreateStack();
    node* tempBTnode;
    int i = 0;
    char token[80] = {0}, *current = postfix;

    while (current[0] != '\0')
    {
        i = 0;
        while (current[0] != ' ' && current[0] != '\0')
        {
            token[i] = current[0];
            current++;
            i++;
        }
        token[i] = '\0';

        if (isdigit(token))
        {
            push(s, createNodestack(createBTnode(token)));
        }

        if (Check_If_Opertaor(token[0]))
        {
            tempBTnode = createBTnode(token);
            tempBTnode->left = pop(s)->data;
            tempBTnode->right = pop(s)->data;
            push(s, createNodestack(tempBTnode));
        }
    }
    return pop(s)->data;
}

void preOrder(node *treeNode)
{
    if (treeNode != NULL)
    {
        printf(" ");
        printf("%c\n", treeNode->data);
        preOrder(treeNode->left);
        preOrder(treeNode->right);
    }
}

int main()
{
     char ex[][50] = { { "2 8 + 7 3 ^ *" }, { "98 2 * 8 +" }, { "2 5 * 6 4 / ^ 
     2 3 + +" },
     { "1 2 3 4 + + +" }, { "12 32 + 3 + 4 +" } };

     int i;
     for (i = 0; i < 5; i++){
        node *treeRoot = create_expr_tree(ex[i]);

        //Traversal Operation on expression tree
        printf("\nPre-Order Traversal :   ");
        preOrder(treeRoot);
     }
 }

this is not the full code, but the problem is in the main with this line:

node *treeRoot = create_expr_tree(ex[i]);

when I debug it, this error message appears to me: Exception thrown at 0x003A1B23 in ConsoleApplication202.exe: 0xC0000005: Access violation writing location 0x00000000

Expression: c>= -1 && c<= 225.

if the full code is needed tell me and i will edit it

c
asked on Stack Overflow Dec 7, 2018 by lioritach • edited Dec 7, 2018 by lioritach

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0