fork download
  1. #include <iostream>
  2. using namespace std;
  3. int top;
  4. void check (char str[ ], int n, char stack [ ])
  5. {
  6. for(int i = 0 ; i < n ; i++ )
  7. {
  8. if (str [ i ] ==()
  9. {
  10. top = top + 1;
  11. stack[ top ] =(;
  12. }
  13. if(str[ i ] ==))
  14. {
  15. if(top == -1 )
  16. {
  17. top = top -1 ;
  18. break ;
  19. }
  20. else
  21. {
  22. top = top -1 ;
  23. }
  24. }
  25. }
  26. if(top == -1)
  27. cout << “String is balanced!<< endl;
  28. else
  29. cout << “String is unbalanced!<< endl ;
  30. }
  31.  
  32. int main ( )
  33. {
  34. //balanced parenthesis string.
  35. char str[ ] = { '(' , 'a' , '+', ' ( ', 'b' , '-' , 'c' ,')' , ')'} ;
  36.  
  37.  
  38. char stack [ 15 ] ;
  39. top = -1;
  40. check (str , 9 , stack ); //Passing balanced string
  41. //Passing unbalanced string
  42. return 0;
  43.  
  44. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:8:13: error: stray '\342' in program
             if (str [ i ] == ‘(’)
             ^
prog.cpp:8:13: error: stray '\200' in program
prog.cpp:8:13: error: stray '\230' in program
prog.cpp:8:13: error: stray '\342' in program
prog.cpp:8:13: error: stray '\200' in program
prog.cpp:8:13: error: stray '\231' in program
prog.cpp:11:17: error: stray '\342' in program
                 stack[ top ] = ‘ ( ’;
                 ^
prog.cpp:11:17: error: stray '\200' in program
prog.cpp:11:17: error: stray '\230' in program
prog.cpp:11:17: error: stray '\342' in program
prog.cpp:11:17: error: stray '\200' in program
prog.cpp:11:17: error: stray '\231' in program
prog.cpp:13:13: error: stray '\342' in program
             if(str[ i ] == ‘)’ )
             ^
prog.cpp:13:13: error: stray '\200' in program
prog.cpp:13:13: error: stray '\230' in program
prog.cpp:13:13: error: stray '\342' in program
prog.cpp:13:13: error: stray '\200' in program
prog.cpp:13:13: error: stray '\231' in program
prog.cpp:27:13: error: stray '\342' in program
             cout << “String is balanced!” << endl;
             ^
prog.cpp:27:13: error: stray '\200' in program
prog.cpp:27:13: error: stray '\234' in program
prog.cpp:27:13: error: stray '\342' in program
prog.cpp:27:13: error: stray '\200' in program
prog.cpp:27:13: error: stray '\235' in program
prog.cpp:29:13: error: stray '\342' in program
             cout << “String is unbalanced!” << endl ;
             ^
prog.cpp:29:13: error: stray '\200' in program
prog.cpp:29:13: error: stray '\234' in program
prog.cpp:29:13: error: stray '\342' in program
prog.cpp:29:13: error: stray '\200' in program
prog.cpp:29:13: error: stray '\235' in program
prog.cpp:35:43: warning: multi-character character constant [-Wmultichar]
         char str[  ] = { '(' , 'a' , '+', ' ( ', 'b' , '-' , 'c' ,')' , ')'} ;
                                           ^
prog.cpp: In function 'void check(char*, int, char*)':
prog.cpp:8:37: error: expected primary-expression before ')' token
             if (str [ i ] == ‘(’)
                                     ^
prog.cpp:9:13: error: expected ')' before '{' token
             {
             ^
prog.cpp:27:24: error: 'String' was not declared in this scope
             cout << “String is balanced!” << endl;
                        ^
prog.cpp:29:24: error: 'String' was not declared in this scope
             cout << “String is unbalanced!” << endl ;
                        ^
prog.cpp: In function 'int main()':
prog.cpp:35:76: error: narrowing conversion of '2107424' from 'int' to 'char' inside { } [-Wnarrowing]
         char str[  ] = { '(' , 'a' , '+', ' ( ', 'b' , '-' , 'c' ,')' , ')'} ;
                                                                            ^
stdout
Standard output is empty