s
This commit is contained in:
parent
3e7a6dc76d
commit
7de53efbbc
33
a1/program.c
33
a1/program.c
@ -0,0 +1,33 @@
|
||||
#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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user