获取`错误:预期标识符或'('在'}'标记之前`[已关闭]

问题描述 投票:0回答:1

error: expected identifier or '(' before '}' token
之前获取右大括号上的
void push()
代码:

#include <stdio.h>
#include <stdlib.h>
struct stack
{
    int no;
    struct stack *next;
};
struct stack *p,*temp,*head;
void main()
{
    void push();
    void pop();
    void display();
    int choice;
    while(1);
        printf("\n 1 Push");
        printf("\n 2 Pop");
        printf("\n 3 Display");
        printf("\n 4 Quit");
        printf("\n Enter your option: ");
        scanf("%d", &choice);
        switch (choice)
        {
        case 1:
            push();
            break;
        
        case 2:
            pop();
            break;

        case 3:
            display();
            break;

        default:
            exit(0);
        }
    }
} //getting the error here
void push()
{
    temp=(struct stack*) malloc(sizeof(struct stack));
    printf("\n Enter no: ");
    scanf("%d", &temp->no);
    if (head==NULL)
    {
        head=temp;
        temp->next=NULL;
    }
    else
    {
        temp->next=head;
        head=temp;
    }
    printf("\n Element %d is pushed in to the stack", temp->no);
}
void pop()
{
    p=head;
    if(head==NULL)
    {
        printf("Stack is empty");
    }
    else
    {
        head=head->next;
        printf("Element %d is popped from the stack", p->no);
        free(p);
    }
}
void display()
{
    if(head==NULL)
    {
        printf("\n stack is empty");
    }
    else
    {
        p=head;
        printf("\n the elements present in the stack:\n");
        while(p!=NULL)
        {
            printf("%d", p->no);
            p=p->next;
        }
    }
}

错误:

file2.c:40:1: error: expected identifier or '(' before '}' token
 }
 ^
c identifier
1个回答
1
投票

您的问题是(在

main
中):

while(1);

应该是:

while (1) {
© www.soinside.com 2019 - 2024. All rights reserved.