I am trying to write a C++ program that will determine whether a string from a file; from the set of characters "" form a group. If so, I want to print the
text that is within the out most bracket group into another file. Some examples are:
xxxx[xxxx]xxxx = [xxxx]
[xxxx[xxxx]xxxx = [xxxx[xxxx]
[xxxx[xxxx]xxxx] = [xxxx[xxxx]xxxx]
x[x[x[xxx]xx]x]x]xx = [x[x[xxx]xx]x]
At the moment I can do the "xxxx[xxxx]xxxx = [xxxx]" example and the reading to and from files I am ok with. I am lost on the thought process I should
take in order to see if I have multiple brackets and whether they form a valid group.
Any help would be great.
Currently I have:
using namespace std;
#define OPEN '['
#define CLOSE ']'
cout << "Enter filename to read DATA from: ";
cin >> filenameIn;
cout << endl;
cout << "Enter filename to write DATA to: ";
cin >> filenameOut;
cout << endl;
cout << "ERROR in opening " << filenameIn << endl;
cout << "Opening file: " << filenameIn << endl << endl;
cout << lineOfText << endl << endl;
if (((Start = strchr(lineOfText, OPEN)) != '\0') && (((End = strchr(Start, CLOSE))) != '\0'))
nChar = End - Start + 1;
strncpy(chBuffer, Start, nChar);
chBuffer[nChar] = '\0';
cout << "The characters found are: " << chBuffer << endl << endl;
outData << chBuffer << endl;
if(!(Start && End))
cout << "None found" << endl << endl;
cout << endl << endl << endl;