Note that there are some explanatory texts on larger screens.

plurals
  1. POProgram Compiles and Runs Fine in Windows IDE, But Won't In Linux - C Language
    primarykey
    data
    text
    <p>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:</p> <pre><code>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 </code></pre> <p>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:</p> <blockquote> <p>stackInit(&amp;s);</p> </blockquote> <p>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:</p> <blockquote> <p>math.h</p> </blockquote> <p>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:</p> <blockquote> <p>gcc prog2.c stack.c postfix.c</p> </blockquote> <p>Is there another way I should be doing this? Thank you in advance.</p> <p>Source Code:</p> <pre><code>/* function to convert an infix to postfix */ char *infixToPostfix(char *infixStr) { static char pfline[30]; int i; stack * s; stackInit(&amp;s); char * token = strtok(infixStr, " "); for(i = 0; i &lt; 30; ++i) { pfline[i] = '\0'; } while(token != NULL) { if(isOperand(token) != 0) { strcat(pfline, token); strcat(pfline, " "); } if(isLeftParen(token)) stackPush(&amp;s, token); if(isOperator(token)) { if(!stackIsEmpty(&amp;s)) { if(isOperator(stackPeek(&amp;s))) { if(stackPrecedence(stackPeek(&amp;s)) &gt;= inputPrecedence(token)) strcat(pfline, stackPop(&amp;s)); strcat(pfline, " "); } } stackPush(&amp;s, token); } if(isRightParen(token)) { while(!isLeftParen(stackPeek(&amp;s))) { strcat(pfline, stackPop(&amp;s)); strcat(pfline, " "); } stackPop(&amp;s); } token = strtok(NULL, " "); } while(!stackIsEmpty(&amp;s)) { strcat(pfline, stackPop(&amp;s)); strcat(pfline, " "); } printf("%s\n", pfline); stackDestroy(&amp;s); return pfline; } int evaluatePostfix(char *postfixStr) { stack * s; int x = 0, y = 0, z = 0; stackInit(&amp;s); char * token = strtok(postfixStr, " "); while(token != NULL) { if(isOperand(token) != 0) stackPush(&amp;s, token); if(isOperator(token)) { y = atoi(stackPop(&amp;s)); x = atoi(stackPop(&amp;s)); char *str = malloc(10 * sizeof(char)); sprintf(str, "%d", applyOperator(x, y, token)); stackPush(&amp;s, str); } token = strtok(NULL, " "); } z = atoi(stackPop(&amp;s)); stackDestroy(&amp;s); return z; } </code></pre> <p>Here is my stack.h header file that was provided which is an interface for the stack:</p> <pre><code>/* * This is an interface for a stack of strings. * */ #ifndef _STACK_H #define _STACK_H #include &lt;stdbool.h&gt; 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 */ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload