Author Topic: compile error help  (Read 3413 times)

0 Members and 1 Guest are viewing this topic.

Offline ramandu

  • Street Thug
  • *
  • Posts: 16
    • View Profile
compile error help
« on: February 28, 2010, 11:36:24 pm »
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 ?

Offline Ettans

  • VC:MP Beta Tester
  • Wiseguy
  • *
  • Posts: 56
    • View Profile
Re: compile error help
« Reply #1 on: March 01, 2010, 12:38:53 pm »
Code: [Select]

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;
}

Offline ramandu

  • Street Thug
  • *
  • Posts: 16
    • View Profile
Re: compile error help
« Reply #2 on: March 01, 2010, 07:18:26 pm »
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
« Last Edit: March 01, 2010, 07:24:08 pm by ramandu »

Offline Ettans

  • VC:MP Beta Tester
  • Wiseguy
  • *
  • Posts: 56
    • View Profile
Re: compile error help
« Reply #3 on: March 02, 2010, 09:11:21 am »
Code: [Select]
if(!strlen(cmd)) // Called if cmd is null
Code: [Select]
if(strlen(text[0]) == 0) // Called if text is nullBoth 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.
« Last Edit: March 02, 2010, 09:21:48 am by Ettans »

Offline ramandu

  • Street Thug
  • *
  • Posts: 16
    • View Profile
Re: compile error help
« Reply #4 on: March 02, 2010, 02:43:37 pm »
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.

Offline Ettans

  • VC:MP Beta Tester
  • Wiseguy
  • *
  • Posts: 56
    • View Profile
Re: compile error help
« Reply #5 on: March 02, 2010, 03:42:41 pm »
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:

Code: [Select]
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
« Last Edit: March 02, 2010, 03:44:44 pm by Ettans »