Here is a program that reads the number of open and closed brackets. Everything works, before spaces appear in the string. How to solve?
#include <iostream> #include <stdio.h> using namespace std; int main(int argc, char** argv) { char str[80]; cout << "Enter string: "; cin >> str; int numberRound = 0; int numberSquare = 0; int i; for (i = 0; i < 80; i++) { if (str[i] == '(') { numberRound++; } if (str[i] == ')') { numberRound--; } if (str[i] == '[') { numberSquare++; } if (str[i] == ']') { numberSquare--; } } if (numberRound == 0) { cout << "Round skobok porovny\n"; } else cout << "Round Skobok ne porovny\n"; if (numberSquare == 0) { cout << "Square skobok porovny"; } else cout << "Square skobok ne porovny"; return 0; }