From 01620f4b616618c0556d9b3ae48411a46e7180ea Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Wed, 21 Oct 2020 14:54:51 +0200 Subject: [PATCH] ak --- a2/program.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/a2/program.c b/a2/program.c index 46bcc37..021a706 100644 --- a/a2/program.c +++ b/a2/program.c @@ -68,16 +68,16 @@ int main(){ printf("%s", line); int l = strlen(line); - int i, j = 0; + int i, j = -1; char *a = calloc(l, sizeof(char)); char *b = calloc(l, sizeof(char)); for(i = 0; i < l; i++){ if(line[i] == '{' || line[i] == '(' || line[i] == '[' || line[i] == '<'){ push(line[i]); + j++; a[j] = gettop(); b[j] = right_pair(a[j]); - j++; } if(line[i] == '}' || line[i] == ')' || line[i] == ']' || line[i] == '>'){ if(s.size == -1){ @@ -85,8 +85,8 @@ int main(){ return 0; } - else if(!find_pair(gettop(), line[i])){ - printf("Crossed bracket %c in %d, expected %c\n", line[i], i, b); + else if(!find_pair(gettop(), line[i])){ + printf("Crossed bracket %c in %d, expected %c\n", line[i], i, b[j]); return 0; } else{ @@ -99,7 +99,7 @@ int main(){ int h; while(begin < end){ h = b[begin]; - b[begin] = b[--end]; + b[begin++] = b[--end]; b[end] = h; }