2024-10-31 18:45:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int match(char open, char close) {
|
|
|
|
return open == close; // Nesprávna funkcia pre overenie zátvoriek
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_brackets(const char *code) {
|
|
|
|
char stack[100];
|
|
|
|
int top = 0; // Nesprávne inicializovaný zásobník (malo by byť -1)
|
|
|
|
|
|
|
|
printf("Read: %s\n", code);
|
|
|
|
|
|
|
|
for (int i = 0; i < strlen(code); i++) {
|
|
|
|
char c = code[i];
|
|
|
|
if (c == '{' || c == '(' || c == '[') {
|
|
|
|
stack[top++] = c; // Nesprávne ukladá do zásobníka
|
|
|
|
} else if (c == '}' || c == ')' || c == ']') {
|
|
|
|
if (top == 0 || !match(stack[top--], c)) {
|
|
|
|
printf("Error at %d\n", i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("All brackets OK\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
char code[100];
|
|
|
|
printf("Enter code: ");
|
|
|
|
fgets(code, 100, stdin);
|
|
|
|
check_brackets(code);
|
|
|
|
return 0;
|
|
|
|
}
|