Parenthesis Balancer Programm

Ich habe ein Klammerprüfprogramm über den Stack erstellt. In dem er einen String als Eingabe nimmt und prüft, ob der String oder Ausdruck gleich nein ist. von öffnenden und schließenden Klammern. Wenn ja, wird "Paranthesis are balance" angezeigt. Ansonsten "Paranthesis sind unsymmetrisch". Aber der andere ist sehr seltsam, er gibt nur einige zufällige Werte aus und hat keinen Ausdruck als Eingabe genommen, sondern gibt nur einen Junk-Wert für sich selbst aus. Hier ist der Code

#include <stdio.h>
#include <string.h>
#include <stdbool.h>


// Structure defining Stack data structure
struct Stack {
    int count;
    char data[50];
} s;

/*
Initializes the count index to 0
*/
void initialize() {
 s.count = 0;
}

/*
 Checks if Stack is Full or not
*/
bool Is_Full() {
    if(s.count > 50)
        return true;
    else
        return false;
}

/*
 Checks if Stack is Empty or not
*/
bool Is_Empty() {
 if(s.count == 0){
     return true;
 }
 else{
     return false;
}
}

/*
 Adds an element to stack and then increment count index
*/
bool push(int num) {
    if (Is_Full())
        return false;
    else {
        s.data[s.count + 1] = num;
        s.count++;
        return true;
    }
}

/*
 Removes count element from stack and decrement count index
*/
bool pop() {
    if (Is_Empty())
        return false;
    else {
        s.count = s.count - 1;
        s.data[s.count+1];
    }
    return true;
}

int main(void) {
    char expression[100];
    int i, len;
    initialize();
    printf("Enter an expression \n");
    printf("%s", &expression);
    len = strlen(expression);
    /*
    # for '{' : we push '{' in stack
    # for '}' : we pop a character from stack. For every '}' there must be one '{' earlier.
                This will ensure that
                ** There are equal number of '{' and '}' characters in string.
                ** For every '{' there is a '}' in input string later.

    */
    for(i = 0; i < len; i++){
        if(expression[i] == '(' || expression[i] == '{' || expression[i] == '['){
            push(expression[i]);
        }
            if(expression[i] == ')' || expression[i] == '}' || expression[i] == ']'){

                pop();
        }
    }

    if(Is_Empty()){
        printf("Parenthesis are balanced\n");
    }
    else{
        printf("Parenthesis are unbalanced\n");
    }
    return 0;
}

und hier ist die Ausgabe: -

Antworten auf die Frage(4)

Ihre Antwort auf die Frage