Home » Renegade Discussions » Mod Forum » C++ help
Re: C++ help [message #276620 is a reply to message #276608] |
Wed, 01 August 2007 17:34 |
|
Cat998
Messages: 1082 Registered: January 2004 Location: Austria, Vienna
Karma:
|
General (1 Star) Moderator/Captain |
|
|
Sn1per74* wrote on Thu, 02 August 2007 01:41 |
Cat998 wrote on Wed, 01 August 2007 11:22 |
I also recommend you to use a string tokenizer for the command
checking, it's a pain to always use strncmp
|
What do you mean string tokenizer. BTW, Thanks for all the help guys!
And what's the difference between true and false?
|
You can use my char string tokenizer. It's awesome
It splits any strings into pieces, you can define the delimiter it uses for splitting (for example a space), and you can define the maximum number of pieces, the last one contains the rest of the string.
http://www.blackintel.org/Cat998/strtokenizer.txt
strtokenizer takes 4 arguments:
char *message: The message you want to split into pieces
char *buf: It needs a memory buffer, where it can copy the tokens into, for ingame chat messages 512 bytes is enough I think
unsigned int n: The max number of tokens (The last one contains the rest of the string)
char delimiter: The delimiter character
Example:
Quote: | char *message "!kick Sn1per74 C++ newb";
char buf[512]; //buffer for the function
char **toks;
toks = strtokenizer(message, buf, 3, ' '); //function call
Console_Output("%s has been kicked out of the game for: %s", toks[1], toks[2]);
//kick code here
delete[] toks; //cleanup
|
So toks[0] contains word1 (!kick), toks[1] contains word2 (Sn1per74) and toks[2] contains the rest of the string
When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter then "Yes"
Programming is like sex: one mistake and you have to support it for the rest of your life
Want the best answers? Ask the best questions!
"So long, and thanks for all the fish."
[Updated on: Thu, 02 August 2007 12:27] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Thu Feb 06 00:03:56 MST 2025
Total time taken to generate the page: 0.00799 seconds
|