there is some problem with my code…plz help me debug it
#include<stdio.h>
#include<stdlib.h>
struct Stack{
int size;
int top;
char *arr;
};
int isEmpty(struct Stack *ptr){
if(ptr->top== -1){
return 1;
}
return 0;
}
int isFull(struct Stack *ptr){
if(ptr->top==ptr->size-1){
return 1;
}
return 0;
}
void push(struct Stack* ptr, int val){
if(isFull(ptr)){
printf("Stack Overflow! Cannot push %d to the stack\n", val);
}
else{
ptr->top++;
ptr->arr[ptr->top] = val;
}
}
int pop(struct Stack* ptr){
if(isEmpty(ptr)){
printf("Stack Underflow! Cannot pop from the stack\n");
return -1;
}
else{
int val = ptr->arr[ptr->top];
ptr->top--;
return val;
}
}
int parenthesisMatch(char* exp){
struct Stack * sp ;
sp->size=100;
sp->top=-1;
sp->arr=(char*)malloc(sp->size*sizeof(char));
for(int i=0; exp[i]!='\0';i++){
if(exp[i]=='('){
push(sp,'(');
}
else if(exp[i]==')'){
if(isEmpty(sp)){
return 0;
}
pop(sp);
}
}
if(isEmpty(sp)){
return 1;
}
}
int main(void) {
char * exp = "(8)(";
// Check if stack is empty
if(parenthesisMatch(exp)){
printf("The parenthesis is matching");
}
else{
printf("The parenthesis is not matching");
}
return 0;
}