Code:
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define STACKSIZE 100
typedef int Item_t;
typedef struct{
Item_t number[STACKSIZE];
int Top;
}Stack_t;
void InitializeStack(Stack_t *S);
int EmptyStack(Stack_t S);
int FullStack(Stack_t S);
void Push(Item_t num, Stack_t *S);
void Pop(Stack_t *S, Item_t *num);
int main()
{
Stack_t S;
Item_t num;
double count=0,i;
double c,decimal;
int temp;
InitializeStack(&S);
printf("Enter a base8 number :");
scanf("%lf",&num);
for(i=0;i<num;i++){
if(num<pow(10,i)){
c=num/pow(10,i-1);
if(c==8 || c==9)
printf("Error!!");
else{
Push(c,&S);
count++;
}
}
temp=pow(10,i-1);
num=num%temp;
}
printf("\n\nCount : %lf",count);
printf("\n\nThe result of Pop: \n");
for(i=0; i<count; i++)
{
Pop(&S, &c);
putch(c);
decimal+=c*pow(8, i);
}
printf("\n\nThe equivalent decimal number : %lf\n\n", decimal);
return 0;
}
void InitializeStack(Stack_t *S)
{
S->Top=0;
}
int EmptyStack(Stack_t S)
{
return(S.Top==0);
}
int FullStack(Stack_t S)
{
return (S.Top==STACKSIZE);
}
void Push(Item_t num, Stack_t *S)
{
if(FullStack(*S))
printf("\nERROR: Stack overflow!\n");
else
{
S->number[S->Top]=num;
++(S->Top);
}
}
void Pop(Stack_t *S, Item_t *num)
{
if(EmptyStack(*S))
printf("\nERROR: Empty stack.\n");
else
{
--(S->Top);
*num=S->number[S->Top];
}
}
The error occured on the num=num%temp; line... it says 'Pop' cannot convert parameter 2 from 'double*' to 'int*'...
Can anybody please help me!!!
Thanks in advance!!!