Recommended Posts

Ok so basically, I have a winsock program(that's not the point though, this isn't a network question) that has a master client which sends messages and all the regular clients who just recieve messages. The first command I am trying to put into my server/client is execution, like the windows cmd. The master client sends a message that starts with "start", an example would be "start notepad.exe". What I need to do is strip the string of the characters "start "(including the space), so that the only characters left would be notepad.exe.
This is what I got so far, didn't work but i'm pretty sure I am using the wrong method to erase characters

EDIT: I have to use a char(instead of string) because the message is used for sending bytes over a network aswell
EDIT2: I have also tried using message.erase() but i get this error:
request for member `erase' in `massage', which is of non-class type `char[1024]'
[Edited by - cherryhouse on January 28, 2006 8:54:42 PM]

Share this post

Link to post

Share on other sites

It's not for any in particular reason. I am just trying to pack my program with as many capabilities as I can for experience. This problem I am having is a good example, I didn't know how to remove characters and hopefully I will know how to before I move on to the next function of the program. If i wanted to do a format I would just use SHFormatDrive(). If you feel I am going to use this for dangerous purposes, but know the answer then don't give me the answer :)

Simply put, create a new character array equal or more than your initial, copy over the contents one character at a time with the exception of the last one or whatever the length, and append a null terminator. In your case, just copy over the length of what you want to keep and append whatever you need at the end.

Share this post

Link to post

Share on other sites

If you just want to do it for this specific thing then you can do it easy.

If you know how many characters you want trim off begining for example, you can use strncpy, and when it asks you for source you specify "your string + offset".

Or if you want easy way in this case you can do something like:

char * pszString = "start Notepad.exe";

while(* pszString ++ != ' ');

//pszString now is "Notepad.exe"

Will trim front of string untill it see's a space in this case right after start, leaving pszString with "Notepad.exe".

Hope it helps.

P.S.Of course this is only if you know that your words are seperated by 1 space, and there is even a space... so make checks, if not then you are not sure how many spaces you can write a function similar way as above to trim it.

0

Share this post

Link to post

Share on other sites

This topic is 4337 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.