SA-MP Forums Archive
Using idx in strtok - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Using idx in strtok (/showthread.php?tid=60619)



Using idx in strtok - Accesteam - 05.01.2009

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


Re: Using idx in strtok - Accesteam - 05.01.2009

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


Re: Using idx in strtok - Micko9 - 20.03.2010

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]
?


Re: Using idx in strtok - bilakispa - 20.03.2010

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