Commit 921011df authored by Charles Gerard's avatar Charles Gerard
Browse files

changes

parent 0de12e17
......@@ -11,29 +11,13 @@
#include <vector>
using namespace std;
int main(int argc, const char* argv[]) {
int main() {
vector<char> holder; // holder stores the 6 possible characters: (, ), {, }, [, ]
bool isBalanced = true;
if (argc != 2) {
cout << "wrong length for argc, exiting" << endl;
return -1;
}
cout << "yo" << endl;
string filename = argv[1];
cout << "filename: " << filename << endl;
ifstream ifs(filename);
ifs.open(filename);
char c; //c will represent each character in the input file. we need to investigate "c" at each step
if (!ifs.is_open()) {
cout << "Error opening " << filename << endl;
return -1;
}
while(ifs >> c) {
while(cin >> c) {
if (holder.empty()) {
if (c == ')' || c == '}' || c == ']') {
isBalanced = false;
......@@ -43,14 +27,11 @@ int main(int argc, const char* argv[]) {
if (c == '(') {
cout << "here i am" << endl;
holder.push_back(c);
}
if (c == '[') {
} else if (c == '[') {
holder.push_back(c);
}
if (c == '{') {
} else if (c == '{') {
holder.push_back(c);
}
if (c == ')') {
} else if (c == ')') {
if (holder.back() == '(') {
holder.pop_back();
} else {
......@@ -58,8 +39,7 @@ int main(int argc, const char* argv[]) {
//isBalanced = false;
//break;
}
}
if (c == ']') {
} else if (c == ']') {
if (holder.back() == '[') {
holder.pop_back();
} else {
......@@ -67,8 +47,7 @@ int main(int argc, const char* argv[]) {
//isBalanced = false;
//break;
}
}
if (c == '}') {
} else if (c == '}') {
if (holder.back() == '{') {
holder.pop_back();
} else {
......@@ -84,7 +63,6 @@ int main(int argc, const char* argv[]) {
cout << "what can i say it wasnt empty" << endl;
}
ifs.close();
if (isBalanced) {
cout << "Balanced\n";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment