• Welcome to Vice City Multiplayer.
 

compile error help

Started by ramandu, February 28, 2010, 09:36:24 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ramandu

i have started pawn and i am praticing string manipulation

only problem is, i get this compile error.

error 017: undefined symbol "strtok"

what do i need to do to fix it ?

Ettans



strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' ')){ index++; }
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}

ramandu

#2
thankyou, i have another question.

howto check a value is not null after using strtok?

cmd = strtok(Text, idx);

if (strcmp(cmd, " ", true) == 0) { printf("cmd is empty"); } // it always prints "cmd is empty" even if its not

also, am i able to add the strtok function to a .inc file and globally use it. if so, how.

thankyou very much

Ettans

#3
if(!strlen(cmd)) // Called if cmd is null
if(strlen(text[0]) == 0) // Called if text is null
Both work the same way.

To use strtok globally, make a file called strtok.inc in /pawno/includes and put the strtok function in it, then just add #include <strtok> on-top of your gamemode.

ramandu

Thankyou, i have a couple more questions.

why 256 when declaring strings? 256 represents bytes, yes ? how many chars will fit in 256 bytes? should i make it as low as possible ?

can i access a given string delimiter by using a [1] format.

New
   Index,
   MyString = "this is my string";

   strtok(MyString, Index);

   MyString[0] // does this return the total segments ?
   MyString[1] // does this return the first segmant ?
   MyString[2] // does this return the second segment ?

if not, how do i accomplish it.

thankyou very much.

Ettans

#5
255 characters will fit in a string with a size of 256 bytes. 255+null = 256. For example, if you have a sentence with 63 characters, then you'd only need a string-size if 64. Always keep them as low as possible (to decrease memory usage), 128 is the max length in the chat by the way, so using 128 is just fine. MyString[pos] would be an array, example usage:

new MyString[64];
MyString[0] = "Hello";
MyString[1] = "Kitty";


If you want to read/extract a certain part of the string, you should use strfind or strmid.

http://wiki.sa-mp.com/wiki/Strmid
http://wiki.sa-mp.com/wiki/Strfind