Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7542895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:17:21+00:00 2026-05-30T08:17:21+00:00

I have a program written to evaluate postfix expressions. I have the code fully

  • 0

I have a program written to evaluate postfix expressions. I have the code fully functioning with no compiler warnings when I compile and run it from a Windows IDE (Codeblocks), however, when I try to compile the source code in a Linux environment, I get a ton or warnings. They are listed below:

postfix.c: In function ‘infixToPostfix’:
postfix.c:20: warning: passing argument 1 of ‘stackInit’ from incompatible pointer type
stack.h:25: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:36: warning: passing argument 1 of ‘stackPush’ from incompatible pointer type
stack.h:31: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:40: warning: passing argument 1 of ‘stackIsEmpty’ from incompatible pointer type
stack.h:37: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:42: warning: passing argument 1 of ‘stackPeek’ from incompatible pointer type
stack.h:43: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:44: warning: passing argument 1 of ‘stackPeek’ from incompatible pointer type
stack.h:43: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:45: warning: passing argument 1 of ‘stackPop’ from incompatible pointer type
stack.h:34: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:49: warning: passing argument 1 of ‘stackPush’ from incompatible pointer type
stack.h:31: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:54: warning: passing argument 1 of ‘stackPeek’ from incompatible pointer type
stack.h:43: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:56: warning: passing argument 1 of ‘stackPop’ from incompatible pointer type
stack.h:34: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:59: warning: passing argument 1 of ‘stackPop’ from incompatible pointer type
stack.h:34: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:63: warning: passing argument 1 of ‘stackIsEmpty’ from incompatible pointer type
stack.h:37: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:65: warning: passing argument 1 of ‘stackPop’ from incompatible pointer type
stack.h:34: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:69: warning: passing argument 1 of ‘stackDestroy’ from incompatible pointer type
stack.h:28: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c: In function ‘evaluatePostfix’:
postfix.c:139: warning: passing argument 1 of ‘stackInit’ from incompatible pointer type
stack.h:25: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:146: warning: passing argument 1 of ‘stackPush’ from incompatible pointer type
stack.h:31: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:150: warning: passing argument 1 of ‘stackPop’ from incompatible pointer type
stack.h:34: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:151: warning: passing argument 1 of ‘stackPop’ from incompatible pointer type
stack.h:34: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:154: warning: passing argument 1 of ‘stackPush’ from incompatible pointer type
stack.h:31: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:159: warning: passing argument 1 of ‘stackPop’ from incompatible pointer type
stack.h:34: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
postfix.c:160: warning: passing argument 1 of ‘stackDestroy’ from incompatible pointer type
stack.h:28: note: expected ‘struct stack *’ but argument is of type ‘struct stack **’
/tmp/ccPMgl0G.o: In function `applyOperator':
postfix.c:(.text+0x6bd): undefined reference to `pow'
collect2: ld returned 1 exit status

They all seem to be related to my postfix.c source and my stack.h header. The postfix.c source I completely modified myself, but the stack.h header was supplied by my instructor. All the errors for the postfix.c source seem to point to lines where I have code in the following manner:

stackInit(&s);

I believe it is referring to my use of the ampersand as a parameter for the function… but there isn’t any other way for me to indicate that I am modifying the immediate value of ‘s’ is there? Is there something I should be including before hand? Also… for the ‘pow’ issue, I have included the header file:

math.h

So it should be able to reference it… I don’t know why it won’t compile :/ I have been using this to compile my 3 source files together:

gcc prog2.c stack.c postfix.c

Is there another way I should be doing this? Thank you in advance.

Source Code:

/* function to convert an infix to postfix */
char *infixToPostfix(char *infixStr)
{
    static char pfline[30];
    int i;
    stack * s;
    stackInit(&s);

    char * token = strtok(infixStr, " ");

    for(i = 0; i < 30; ++i) {
        pfline[i] = '\0';
    }

    while(token != NULL)
    {
        if(isOperand(token) != 0) {
            strcat(pfline, token);
            strcat(pfline, " ");
        }

        if(isLeftParen(token))
            stackPush(&s, token);

        if(isOperator(token))
        {
            if(!stackIsEmpty(&s))
            {
                if(isOperator(stackPeek(&s)))
                {
                    if(stackPrecedence(stackPeek(&s)) >= inputPrecedence(token))
                        strcat(pfline, stackPop(&s));
                        strcat(pfline, " ");
                }
            }
            stackPush(&s, token);
        }

        if(isRightParen(token))
        {
            while(!isLeftParen(stackPeek(&s)))
            {
                strcat(pfline, stackPop(&s));
                strcat(pfline, " ");
            }
            stackPop(&s);
        }
        token = strtok(NULL, " ");
    }
    while(!stackIsEmpty(&s))
    {
        strcat(pfline, stackPop(&s));
        strcat(pfline, " ");
    }
    printf("%s\n", pfline);
    stackDestroy(&s);
    return pfline;
}

int evaluatePostfix(char *postfixStr)
{
    stack * s;
    int x = 0, y = 0, z = 0;

    stackInit(&s);
    char * token = strtok(postfixStr, " ");

    while(token != NULL)
    {

        if(isOperand(token) != 0)
            stackPush(&s, token);

        if(isOperator(token))
        {
            y = atoi(stackPop(&s));
            x = atoi(stackPop(&s));
            char *str = malloc(10 * sizeof(char));
            sprintf(str, "%d", applyOperator(x, y, token));
            stackPush(&s, str);
        }
        token = strtok(NULL, " ");
    }

    z = atoi(stackPop(&s));
    stackDestroy(&s);
    return z;
}

Here is my stack.h header file that was provided which is an interface for the stack:

/*
 * This is an interface for a stack of strings.
 *
 */

#ifndef _STACK_H
#define _STACK_H

#include <stdbool.h>

typedef char * stkElement;

struct stkNode {
  stkElement element;
  struct stkNode *next;
};

typedef struct stkNode stkNode;

typedef struct {
  stkNode *top;
} stack;

/* function to initialize a new stack variable */
void stackInit(stack *stkPtr);

/* function to free the memory associated with the stack */
void stackDestroy(stack *stkPtr);

/* function to add an element to the top of the stack */
void stackPush(stack *stkPtr, stkElement element);

/* function that removes the element from the top of the stack */
stkElement stackPop(stack *stkPtr);

/* function that returns a true value if the stack is empty */
bool stackIsEmpty(stack *stkPtr);

/* function that returns the number of elements in the stack */
int stackLength(stack *stkPtr);

/* function that returns the top element in the stack without removing it */
stkElement stackPeek(stack *stkPtr);

#endif  /* _STACK_H */
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:17:23+00:00Added an answer on May 30, 2026 at 8:17 am

    It is likely not the call to stackInit() that is actually wrong – rather it is the declaration of s. You are correct that you need to use stackInit(&s); if you want stackInit() to modify the variable s in the calling function, but if stackInit() takes a parameter of type stack * then that indicates that you should be declaring s as:

    stack s;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program written in C, which is named computeWeight.c and to compile
I have a program written in C#, running on a Windows CE device (on
I have a program written in C that runs on Linux, MacOS and Windows.
Situation: I have a program written in VB6 The source code of the program
I have a program written in C#. I want the Timer class to run
I have a program written in VB 2010 express under windows xp which does
I have my program written in C++ and it is can be successfully compiled
I have a program written in C++, on Linux, compiled with -g. When I
I have a program written in VB.Net (Visual Studio 2008) that uses a DLL
I'm using Visual Studio 2005. I have a program written in C#. When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.