Obteniendo `error: identificador esperado o '(' antes de '}' token` [cerrado]
Obteniendo la error: expected identifier or '(' before '}' token
llave de cierre antes void push()
del código:
#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;
}
}
}
El error:
file2.c:40:1: error: expected identifier or '(' before '}' token
}
^
Aceptado
Tu problema es que (en main
):
while(1);
Debiera ser:
while (1) {