Update 'a1/program.c'
This commit is contained in:
parent
215c3c7fab
commit
4aeaedded0
13
a1/program.c
13
a1/program.c
@ -1,9 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
|
||||
int open_brackets(char a) {
|
||||
return (a == '(' || a == '[' || a == '{' || a == '<');
|
||||
@ -39,7 +36,6 @@ int main() {
|
||||
char letters[100];
|
||||
int letter_index = 0;
|
||||
|
||||
printf("Read: ");
|
||||
for (int i = 0; code[i] != '\0'; i++) {
|
||||
if (isalpha(code[i])) {
|
||||
letters[letter_index++] = code[i];
|
||||
@ -47,7 +43,7 @@ int main() {
|
||||
if (open_brackets(code[i])) {
|
||||
stack[++skobochka] = i;
|
||||
} else if (close_brackets(code[i])) {
|
||||
if (skobochka == -1) {
|
||||
if (skobochka == -1) {
|
||||
error = i;
|
||||
break;
|
||||
}
|
||||
@ -60,14 +56,15 @@ if (skobochka == -1) {
|
||||
}
|
||||
|
||||
if (error == -1 && skobochka == -1) {
|
||||
printf("Read: ");
|
||||
for (int i = 0; i < letter_index; i++) {
|
||||
printf("%c", letters[i]);
|
||||
}
|
||||
printf("\nAll brackets OK\n");
|
||||
} else if (error == -1) {
|
||||
printf("Crossed bracket %c in %d, expected %c\n", code[error], error, brackets(code[error]));
|
||||
printf("Crossed bracket %c in %d, expected %c\n", code[error], error, brackets(code[error]));
|
||||
} else {
|
||||
printf("Bracket on position %d not closed\n", stack[skobochka]);
|
||||
printf("Unexpected closing bracket in % d \n", stack[skobochka]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user