this is my code...i am getting that error at 'void push(int item, STACK *S)'.
#include<stdio.h>
#include<conio.h>
#include<process.h>
#define STACK_SIZE 5
struct stack
{
int arr[STACK_SIZE];
int top;
};
type def struct stack,STACK;
void push(int item, STACK *S)
{
if(S->top==STACK_SIZE-1)
{
printf("stack overflow\n");
return;
}
S->top++;
S->arr[S->top]=item;
}
void pop(STACK *S)
{
int item;
if(S->top==-1)
{
printf("stack overflow\n");
return;
}
printf("deleted element is %d \n ",S->arr[S->top--]);
}
void display(STACK *S)
{
int i;
if(S->top==-1)
{
printf("stack underflow\n");
return;
}
printf("the contest of the stack \n");
for(i=s->top;i>=0;i--)
{
printf("%d\n",S->arr[i]);
}
}
void main()
{
int item,ch;
STACK S;
clrsacr();
S.to=-1;
for(;;)
{
printf("1:push\n 2:pop\n 3:display\n 4:exit\n");
printf("enter the choice\n");
scanf("%d",ch);
switch(ch)
{
case 1: printf("enter the item to be inserted\n");
scanf("%d",&item);
push(item,&S);
break;
case 2: pop(&s);
break;
case 3: display(&S);
break;
default: exit(0);
}
}
getch();
}
in this i'm getting another error...declaration terminated incorrectly at "type def struct stack,STACK;'. i got this error while compiling this program in turbo c. i am a bit new to stacks.
type def struct stack,STACK;
^ typedef is a keyword not type def
Use:-
typedef struct stack STACK;