fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. const int MAXSIZE=100;
  4. struct Stack
  5. {
  6. char data[MAXSIZE];
  7. int size;
  8. }
  9. char Pop (Stack &S)
  10. {
  11. if (S.size==0)
  12. {
  13. printf ("Stack empty");
  14. return char(255);
  15. }
  16. S.size--;
  17. return S.data[S.size];
  18. }
  19.  
  20. void Push (Stack &S, char x)
  21. {
  22. if (S.size==MAXSIZE)
  23. {
  24. printf ("Stack>>>");
  25. return;
  26. }
  27. S.data[S.size]=x;
  28. S.size++;
  29. }
  30. int main(void)
  31. {
  32. char br1[3] = { '(', '[', '{' };
  33. char br2[3] = { ')', ']', '}' };
  34. char s[80], upper;
  35. int i, k, OK;
  36. Stack S;
  37. printf("Enter stack: ");
  38. gets(s);
  39. S.size=0;
  40. OK=1;
  41. for (i=0; OK&&(s[i]!='\0'); i++)
  42. for (k=0; k<3; k++)
  43. {
  44. if (s[i]==br1[k])
  45. {
  46. Push (S, s[i]);
  47. break;
  48. }
  49. if (s[i]==br2[k])
  50. {
  51. upper=Pop(S);
  52. if (upper!=br1[k])
  53. OK=0;
  54. break;
  55. }
  56. }
  57. if (OK&&(S.size == 0))
  58. printf("\nRight\n");
  59. else printf("\nWrong\n");
  60. }
  61.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:6:14: error: variably modified ‘data’ at file scope
         char data[MAXSIZE];
              ^
prog.c:9:1: error: expected ‘;’, identifier or ‘(’ before ‘char’
 char Pop (Stack &S)
 ^
prog.c:9:17: error: expected ‘)’ before ‘&’ token
 char Pop (Stack &S)
                 ^
prog.c:20:18: error: expected ‘)’ before ‘&’ token
 void Push (Stack &S, char x)
                  ^
prog.c: In function ‘main’:
prog.c:36:9: error: unknown type name ‘Stack’
         Stack S;
         ^
prog.c:38:9: warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
         gets(s);
         ^
prog.c:39:10: error: request for member ‘size’ in something not a structure or union
         S.size=0;
          ^
prog.c:46:25: warning: implicit declaration of function ‘Push’ [-Wimplicit-function-declaration]
                         Push (S, s[i]);
                         ^
prog.c:51:25: warning: implicit declaration of function ‘Pop’ [-Wimplicit-function-declaration]
                         upper=Pop(S);
                         ^
prog.c:57:15: error: request for member ‘size’ in something not a structure or union
     if (OK&&(S.size == 0))
               ^
prog.c:60:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty