s
This commit is contained in:
parent
1d86789433
commit
26123b26c8
@ -10,6 +10,7 @@ void check_brackets(const char *code) {
|
||||
char stack[100];
|
||||
int top = -1;
|
||||
|
||||
// Výpis pre načítaný kód
|
||||
printf("Read: %s\n", code);
|
||||
|
||||
for (int i = 0; code[i] != '\0'; i++) {
|
||||
@ -18,11 +19,11 @@ void check_brackets(const char *code) {
|
||||
stack[++top] = c;
|
||||
} else if (c == '}' || c == ']' || c == ')' || c == '>') {
|
||||
if (top == -1) {
|
||||
printf("Unexpected closing bracket %c in %d\n", c, i);
|
||||
fprintf(stderr, "Unexpected closing bracket %c in %d\n", c, i);
|
||||
return;
|
||||
}
|
||||
if (!match(stack[top], c)) {
|
||||
printf("Crossed bracket %c in %d, expected %c\n", c, i, stack[top]);
|
||||
fprintf(stderr, "Crossed bracket %c in %d, expected %c\n", c, i, stack[top]);
|
||||
return;
|
||||
}
|
||||
top--;
|
||||
@ -31,14 +32,14 @@ void check_brackets(const char *code) {
|
||||
if (top == -1) {
|
||||
printf("All brackets OK\n");
|
||||
} else {
|
||||
printf("Missing closing brackets: %c\n", stack[top]);
|
||||
fprintf(stderr, "Missing closing brackets: %c\n", stack[top]);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
char code[100];
|
||||
if (fgets(code, sizeof(code), stdin) != NULL) {
|
||||
|
||||
// Odstráň nový riadok, ak existuje
|
||||
size_t len = strlen(code);
|
||||
if (len > 0 && code[len - 1] == '\n') {
|
||||
code[len - 1] = '\0';
|
||||
|
Loading…
Reference in New Issue
Block a user