Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions

Question

1. Describe a comprehensive approach to retaining employees.pg 87

Answered: 1 week ago