T
Tarique
Hello all.I am trying to implement a stack which can store either
integer or float values.
The code is given below:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define STACKSIZE 100
#define INT 1
#define FLOAT 2
#define STRING 3
struct stackelement{
int etype; /*etype equals INT,FLOAT,STRING*/
/*depending on the type of the */
/*corresponding element */
union {
int iVal;
float fVal;
/* char *pVal; */
}element;
};
struct stack{
int top;
struct stackelement item[STACKSIZE];
};
void push(struct stack *p,struct stackelement *se,int n)
{
if(p->top == STACKSIZE-1 )
printf("overflow\n");
else
{
if(se->etype == INT)
p->item[++p->top].element.iVal=n;
else if(se->etype == FLOAT)
p->item[++p->top].element.fVal=(float)n;
/*
else if(se->etype == STRING)
p->item[++p->top].element.pVal="T";
*/
}
return;
}
void pop(struct stack *p,struct stackelement *se)
{
if(p->top==-1)
printf("underflow\n");
else
{
if(se->etype == INT)
printf("deleted number is\ %d\n",p->item[p->top].element.iVal);
else if(se->etype == FLOAT)
printf("deleted number is\ %d\n",p->item[p->top].element.fVal);
--p->top;
}
return;
}
void display(struct stack *p,struct stackelement *se)
{
int i;
if(p->top == -1)
printf("stack is empty\n\n");
else
{
if(se->etype == INT)
{
for(i=p->top; i >= 0; i--)
printf("%d\n", p->item.element.iVal\ );
}
else
{
for(i = p->top; i >= 0; i--)
printf("%d\n", p->item.element.fVal);
}
}
return;
}
void menu(void)
{
/*Sub Menu
to accept the options of push /pop etc*/
}
int main(void)
{
int choice_mm ;
struct stackelement se;
struct stack s;
s.top = -1;
/*Main Menu
to accept the choices for int/float type*/
return 0;
}
I am getting the warning:
warning C4133: 'function' : incompatible types - from 'stack *' to
'stackelement *'
whenever i try to call the push /pop/display functions
push(&s,&s_elem,num);
pop(&s,&s_elem);
display(&s,&s_elem);
in the main function
Can anyone please help me out?Thanks
integer or float values.
The code is given below:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define STACKSIZE 100
#define INT 1
#define FLOAT 2
#define STRING 3
struct stackelement{
int etype; /*etype equals INT,FLOAT,STRING*/
/*depending on the type of the */
/*corresponding element */
union {
int iVal;
float fVal;
/* char *pVal; */
}element;
};
struct stack{
int top;
struct stackelement item[STACKSIZE];
};
void push(struct stack *p,struct stackelement *se,int n)
{
if(p->top == STACKSIZE-1 )
printf("overflow\n");
else
{
if(se->etype == INT)
p->item[++p->top].element.iVal=n;
else if(se->etype == FLOAT)
p->item[++p->top].element.fVal=(float)n;
/*
else if(se->etype == STRING)
p->item[++p->top].element.pVal="T";
*/
}
return;
}
void pop(struct stack *p,struct stackelement *se)
{
if(p->top==-1)
printf("underflow\n");
else
{
if(se->etype == INT)
printf("deleted number is\ %d\n",p->item[p->top].element.iVal);
else if(se->etype == FLOAT)
printf("deleted number is\ %d\n",p->item[p->top].element.fVal);
--p->top;
}
return;
}
void display(struct stack *p,struct stackelement *se)
{
int i;
if(p->top == -1)
printf("stack is empty\n\n");
else
{
if(se->etype == INT)
{
for(i=p->top; i >= 0; i--)
printf("%d\n", p->item.element.iVal\ );
}
else
{
for(i = p->top; i >= 0; i--)
printf("%d\n", p->item.element.fVal);
}
}
return;
}
void menu(void)
{
/*Sub Menu
to accept the options of push /pop etc*/
}
int main(void)
{
int choice_mm ;
struct stackelement se;
struct stack s;
s.top = -1;
/*Main Menu
to accept the choices for int/float type*/
return 0;
}
I am getting the warning:
warning C4133: 'function' : incompatible types - from 'stack *' to
'stackelement *'
whenever i try to call the push /pop/display functions
push(&s,&s_elem,num);
pop(&s,&s_elem);
display(&s,&s_elem);
in the main function
Can anyone please help me out?Thanks