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
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started