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; }