Using idx in strtok
#1

I see the following alot in scripts:
Код:
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
	SendClientMessage(playerid, COLOR_WHITE, "USAGE: /command [correct parameters]");
	return 1;
}
Its used to recognize if commands are used correctly. If I'am correct it splits (tokenize) the command with strtok and then count the characters behind the command itself to check if parameters are filled in correctly. But I got no idea what idx stands for... Because on the place where where idx is standing there should be filled in the chars where to "split" the string, right?

So to be clear, my question is: What does idx, and where does it stand for?
I hope someone can explain this to me.

Thanks in advance!

-----
Accesteam
Reply
#2

Quote:
Originally Posted by ssǝן‾ʎ
strtok only splits by space, so it has no need for a character list. idx is the position in the string that the split got to last time, so the next time you call it it will get the next word rather than the same word again. However I urge you to not worry about strtok and read this instead.
Awesome! Thnx for the explanation and the link
Reply
#3

Quote:
Originally Posted by Accesteam
I see the following alot in scripts:
Код:
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
	SendClientMessage(playerid, COLOR_WHITE, "USAGE: /command [correct parameters]");
	return 1;
}
Its used to recognize if commands are used correctly. If I'am correct it splits (tokenize) the command with strtok and then count the characters behind the command itself to check if parameters are filled in correctly. But I got no idea what idx stands for... Because on the place where where idx is standing there should be filled in the chars where to "split" the string, right?

So to be clear, my question is: What does idx, and where does it stand for?
I hope someone can explain this to me.

Thanks in advance!

-----
Accesteam
how to do a double ex : "/command [param 1] [param2]" ? like :
[pawn]
strtok(tmp, idx);
[pawn]
?
Reply
#4

Quote:
Originally Posted by Micko9
Quote:
Originally Posted by Accesteam
I see the following alot in scripts:
Код:
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
	SendClientMessage(playerid, COLOR_WHITE, "USAGE: /command [correct parameters]");
	return 1;
}
Its used to recognize if commands are used correctly. If I'am correct it splits (tokenize) the command with strtok and then count the characters behind the command itself to check if parameters are filled in correctly. But I got no idea what idx stands for... Because on the place where where idx is standing there should be filled in the chars where to "split" the string, right?

So to be clear, my question is: What does idx, and where does it stand for?
I hope someone can explain this to me.

Thanks in advance!

-----
Accesteam
how to do a double ex : "/command [param 1] [param2]" ? like :
[pawn]
strtok(tmp, idx);
[pawn]
?
http://forum.sa-mp.com/index.php?topic=74878.0
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)