Question: Hi, so i am going through my code step by step to avoid missing up. here my code crashes when i enter my input if

Hi, so i am going through my code step by step to avoid missing up.

here my code crashes when i enter my input

if you could take a look and tell me what causes crashing my program

#include #include #include #define TRUE 1 #define FALSE 0 #define MAX 300

typedef struct StackStruct { char* expression; /* pointer to dynamic array */ int size; /* amount of space allocated */ int top; /* top of stack indicator */ } Stack;

void init (Stack* s) { s->size = 2; s->expression = (char*) malloc ( sizeof (char) * s->size ); s->top = 0; }

void push (Stack* s, char val) { /* check if enough space currently on stack and grow if needed */

/* add val onto stack */ s->expression[s->top] = val; s->top = s->top + 1; }

int isEmpty (Stack* s) { if ( s->top == 0) return TRUE; else return FALSE; }

int top (Stack* s) { return ( s->expression[s->top-1] ); }

void pop (Stack* s) { s->top = s->top - 1; }

int checkBalanced( char expression[] ) { Stack *s; int i; char paranthesis; for( i=0; i'||paranthesis==']'||paranthesis==')') { if(isEmpty (&s)){ return FALSE; } else{ pop (&s); } } } return isEmpty (s) ? TRUE:FALSE; }

int main(int argc,char *argv[]){ Stack *s; init (&s);

char expression[300]; fgets(expression, MAX, stdin); checkBalanced(expression);

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!