nai*_*n33 1 c structure function
我无法将结构传递给一个以结构指针作为参数的函数,并且不断收到错误"错误:一元的无效类型参数'*'(有'StackNode')"
这是我的代码的必要部分(不是全部):
#include <stdio.h>
#include <stdlib.h>
struct stackNode{
char data;
struct stackNode *nextPtr;
};
typedef struct stackNode StackNode;
typedef StackNode *StackNodePtr;
void convertToPostfix(char infix[], char postfix[]);
int isOperator(char c);
int precedence(char operator1, char operator2);
void push(StackNodePtr *topPtr, char value);
char pop(StackNodePtr *topPtr);
char stackTop(StackNodePtr topPtr);
int isEmpty(StackNodePtr topPtr);
void printStack(StackNodePtr topPtr);
int main(){
convertToPostfix(NULL, NULL);
return 0;
}
void convertToPostfix(char infix[], char postfix[]){
StackNode stack = {'(', NULL};
push(*stack, 'a');
printStack(&stack);
}
void push(StackNodePtr* topPtr, char value){
topPtr->nextPtr = NULL; //just temporary, not needed
topPtr->data = value; //just temporary, not needed
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激,谢谢
cni*_*tar 10
更改push通话,push(*stack, 'a'):
push(&stack, 'a');
^
Run Code Online (Sandbox Code Playgroud)
间接on stack(*)没有意义,因为它不是指针.取其地址(&)的确如此.