• Advertisement

Archived

This topic is now archived and is closed to further replies.

parsing in C++

This topic is 6352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

recvmsg = "PING :########";(the #''s are random numbers & letters) what i want to know how to do is take the value of recvmsg, and store the ######## in a variable. The ######## arn''t known at compile time, they are learned while its running. Any ideas? ThX

Share this post


Link to post
Share on other sites
Advertisement
When I have to do stuff like that, I use my nifty little right() function. It returns the right n characters of a string. So you would use it like:

char* right(char* Txt, int Num)
{
char *Buf;
int l=strlen(Txt);
Buf=new char[Num];

for(int i=(l-Num);i{
Buf[i-(l-Num)]=Txt ;
}

Buf[Num]='\0';

return Buf;
}

char* Msg=right(recvmsg,strlen(recvmsg)-6);
// -6 because your 'PING :' is 6 characters long

Hope this helps!

EDIT: stupid text formatting...

Martee
Magnum Games



Edited by - Martee on August 27, 2000 11:11:14 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by uG

recvmsg = "PING :########";(the #''s are random numbers & letters)

what i want to know how to do is take the value of recvmsg, and store the ######## in a variable. The ######## arn''t known at compile time, they are learned while its running. Any ideas?
ThX


The function for this is sscanf. I believe the below will do.

Example:
sscanf(recvmsg, "PING :%s", stringVar);

Torvald

Share this post


Link to post
Share on other sites
Ok...my text above got a bit screwed...
that for loop should be
for(int i=(l-num);i
EDIT:
Moderators/Admin people...why won't my text display properly? Did I do something wrong? Are you not allowed to use the less-than symbol?

Martee
Magnum Games



Edited by - Martee on August 27, 2000 11:17:20 PM

Share this post


Link to post
Share on other sites
The less-than symbol is used for HTML tags, so you can display links for example. I believe you can put less-than symbols correctly inside [ source] [ /source] tags. Let me try:

                
Less-than symbol: <


Yep, it works.

Edited by - Muzzafarath on August 28, 2000 2:00:55 AM

Share this post


Link to post
Share on other sites

  • Advertisement