我正在开始我的堆栈代码,但这是一个问题
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct stackNode
{
int data;
struct stackNode *nextPtr;
};
typedef struct stackNode StackNode;
typedef StackNode *StackNodePtr;
void instructions()
{
printf("Please enter a choice\n");
printf("[1]Push a value on the stack\n");
printf("[2]Pop a value off the stack\n");
printf("[3]Display the whole stack\n");
printf("[4]Exit");
}
void push(StackNodePtr *topPtr, int info)
{
StackNodePtr newPtr;
newPtr=malloc (sizeof ( StackNode ));
if(newPtr !=NULL)
{
newPtr->data=info;
newPtr->nextPtr=*topPtr;
*topPtr = newPtr;
}
}
int main()
{
instructions();
system("pause");
}
我的代码有什么问题?
这就是问题
newPtr = malloc(sizeof (StackNode));
void*
它声明从到的无效转换StackNode*
编译,看看它是否会工作
我该如何解决?我应该编辑什么?