I did not create this code, but I am trying to modify it to work like I want it to, so don't ask me the how the whole thing works.
Here is the code I am working on:
Code:
//parser class--------------------------------------------
class parser
{
std::string text;
public:
static const int max_field_size=100;
explicit parser(const char *s) : text(s) {}
void tokenize(char *fields[], int nf, const char breaker=' ')
{
// parses internal string, breaking at instances of <breaker>
// which are thrown away. Returns separated values as fields
std::istringstream buffer(text);
int f=0;
while (f<nf)
{
buffer.getline(fields[f], max_field_size, breaker);
++f;
}
}
};
//end of parser class--------------------------------------
int main()
{
...
cin >> string s;
parsef(s);
...
}
//string parsing Function----------------------------------
void parsef(string s)
{
const char* userstring="RUN filename and this\n";
char **fields = new char*[3];
for (int i=0; i<3; ++i)
fields[i]=new char[parser::max_field_size];
parser parse(userstring);
parse.tokenize(fields, 3);
for (int i=0; i<3; ++i)
cout << "word " << i << ": " << fields[i] << endl;
}
//end string parsing Function------------------------------
I thinking it's something simple to do, but I just can't figure it out.
Could someone help, please? And thanks.



