1

我收到以下错误消息。无法解决它。谷歌了很多。终于想到放在这里了。

在此处输入图像描述

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int stop;
struct stack
{
  int data;
  struct stack *next;
};
typedef struct stack *node, *top;
//typedef struct stack *top;
void push()
{
    int i;
    struct stack *x;
    x = malloc(sizeof(struct stack));
    printf("\n Enter the element your want to insert");
    scanf("%d", &i);
    x->data = i;
    x->next = top;
    top = x;
}
void pop()
{
    int i;
    if(top == NULL)
    {
        printf("\nStack is empty\n");
    }
    else{
    i = top->data;
    free(top);
    top = top->next;

    }
}
void display()
{
    if(node != NULL)
    {
        printf("%d ", node->data);
        node = node->next;
    }

}
int main()
{
    int ch;
    while(1)
    {
        printf("\nEnter your option \n1. Insert(Push) \n2. Delete(Pop) \n3. Display  : \n");
        scanf("%d", &ch);
        switch(ch)
        {
            case 1:
                    push();
                    break;
            case 2:
                    pop();
                    break;
            case 3:
                    display();
                    break;
            default:
                    printf("Invalid Entery, Try Again");
        }
    }
return 0;
}
4

3 回答 3

5

删除typedef,一切都会好起来的。

于 2012-04-24T13:47:27.273 回答
3

你不想要一个新的类型:

typedef struct stack *node, *top;

相反,您需要一个新变量:

struct stack *node, *top;
于 2012-04-24T13:48:30.380 回答
1

您不能将变量声明与typedef. 如果你想创建一个别名struct stack并简单地调用它stack,修改你的代码如下:

struct stack {
    int data;
    struct stack *next;
};
typedef struct stack stack;
stack *node, *top;
于 2012-04-24T13:48:08.893 回答