A
Adam Balgach
Hello hello,
i am trying to parse up a line that is in the format:
@xxxxx yyyyyy {zzzzz, aaaaaa, bbbbbb}
where there could be any number of elements inbetween the { ... }
i am only concerned with getting the yyyyy and then the tokens in the
{ }
so the code im using is:
in->getline(line, 1024); //to get the inital line.
char *name;
name = strtok(line, " ");
int count=0;
char *firstThing;
while(name!=NULL) {
name = strtok(NULL, " {,}";
if (count==0) {
//do somehting with yyyyyy
cout << "First Thing: "<<name<<endl;
firstThing=name;
}
else if (count>0) {
cout << "{"<<firstThing<<", "<<name<<"}\n";
//do something with name (should = zzzzzzz then aaaaaaa hten
bbbbbbb)
}
count++;
}
now when i run this code it outputs:
First Thing: yyyyyy
{yyyyyy,zzzzzz}
{yyyyyy,aaaaaa}
{yyyyyy,bbbbb}
{yyyyyy,
any idea why its running through this loop one too many times... ie
the last entry shouldnt be htere?
cheers,
Adam.
i am trying to parse up a line that is in the format:
@xxxxx yyyyyy {zzzzz, aaaaaa, bbbbbb}
where there could be any number of elements inbetween the { ... }
i am only concerned with getting the yyyyy and then the tokens in the
{ }
so the code im using is:
in->getline(line, 1024); //to get the inital line.
char *name;
name = strtok(line, " ");
int count=0;
char *firstThing;
while(name!=NULL) {
name = strtok(NULL, " {,}";
if (count==0) {
//do somehting with yyyyyy
cout << "First Thing: "<<name<<endl;
firstThing=name;
}
else if (count>0) {
cout << "{"<<firstThing<<", "<<name<<"}\n";
//do something with name (should = zzzzzzz then aaaaaaa hten
bbbbbbb)
}
count++;
}
now when i run this code it outputs:
First Thing: yyyyyy
{yyyyyy,zzzzzz}
{yyyyyy,aaaaaa}
{yyyyyy,bbbbb}
{yyyyyy,
any idea why its running through this loop one too many times... ie
the last entry shouldnt be htere?
cheers,
Adam.