From 29351306ac375c3e3fd7217095e1d103c975b65f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Korpesio?= Date: Sun, 28 Nov 2021 18:00:09 +0100 Subject: [PATCH] prvy --- a2/program.c | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/a2/program.c b/a2/program.c index f76ee04..412bdb5 100644 --- a/a2/program.c +++ b/a2/program.c @@ -17,18 +17,13 @@ int main(){ n = strlen(r); //printf("%ld", n); while(r[i] != '\n'){ - //puts("1"); if (r[0] != '{' || r[0] != '(' || r[0] != '[' || r[0] != '<') { - i = n - 2; + //i = n - 2; + hej = 1; //puts("halo"); } - if (r[0] == '}' || r[n - 2] == '}'){ - hej = 3; - printf("Read: %s", r); - printf("Unexpected closing bracket } in %d\n", i); - i = n - 2; - } + if (r[i] == '{') { hodnota = 1; i++; @@ -48,18 +43,18 @@ int main(){ //printf("hodnota: %d\n", hodnota); if (hodnota == 1){ - hodnota = 0; + //hodnota = 0; for (a = p; a'){ - puts("nie"); + //puts("nie"); hej = 0; a = n; i = n - 1; @@ -68,16 +63,17 @@ int main(){ } } else if (hodnota == 2){ - hodnota = 0; + //hodnota = 0; for (a = p; a>n; a++){ if (r[a] == ')') { + //puts("hod 2"); hej = 1; //r[a] = 'a'; p = a; a = n; } else if (r[a] == '}' || r[a] == ']' || r[a] == '>'){ - puts("nasiel"); + //puts("nasiel"); hej = 0; a = n; i = n - 1; @@ -85,11 +81,12 @@ int main(){ } } else if (hodnota == 3) { - hodnota = 0; + //hodnota = 0; for (a = p; a < n; a++) { //puts("neidem"); if (r[a] == ']') { //puts("nasiel som"); + puts("hod 3"); hej = 1; //r[a] = 'a'; p = a; @@ -105,16 +102,17 @@ int main(){ } } else if (hodnota == 4){ - hodnota = 0; + //hodnota = 0; for (a = p; a>n; a++){ if (r[a] == '>') { + //puts("hod 4"); hej = 1; //r[a] = 'a'; p = a; a = n; } else if (r[a] == '}' || r[a] == ']' || r[a] == ')'){ - puts("nasiel"); + //puts("nasiel"); hej = 0; a = n; i = n - 1; @@ -122,9 +120,23 @@ int main(){ } } - else{ + if (hodnota == 0){ + + if (r[i] == '}' || r[i] == ')' || r[i] == ']' || r[i] == '>') { + hej = 3; + //puts("ahoj"); + printf("Read: %s", r); + if (r[i] == '}'){printf("Unexpected closing bracket } in %d\n", i+1);} + else if (r[i] == ')'){printf("Unexpected closing bracket ) in %d\n", i+1);} + else if (r[i] == ']'){printf("Unexpected closing bracket ] in %d\n", i+1);} + else if (r[i] == '>'){printf("Unexpected closing bracket > in %d\n", i+1);} + i = n - 2; + } i++; } + //else{ + // i++; + //} } if (hej == 1){ printf("Read: %s", r);