I am tasked to write a simple program that reads in a file, and determines if the characters '(' '[' and '{' and "balanced". Meaning, There is a matching closing bracket/brace/parentheses for each opening one.
I am having trouble with the input. We are to use input redirection, not an iostream object, taking advantage of the command line. We utilize a makefile and when I run the executable it tells me 2 errors: not using argc and argv[].
struct Contents {
int numP;
int numS;
int numC;
};
int main(int argc, const char* argv[]) {
char word;
Contents c;
while(cin >> word) {
if(word == '{' || word == '}') {
c.numC++;
}
if(word == '(' || word == ')') {
c.numP++;
}
if(word == '[' || word == ']') {
c.numS++;
}
}
if(c.numC % 2 == 0 || c.numP % 2 == 0 || c.numS % 2 == 0) {
cout << "Balanced" << endl;
}
else {
cout << "Not Balanced" << endl;
}
return 0;
}
What am I missing here to make the file redirection input work? When I run this in XCode I just enter a bunch of values and it never ends. I can't seem to do the input right.
Thank you!