SA-MP Forums Archive
NULL in pawn, undefined 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)
+--- Thread: NULL in pawn, undefined strtok (/showthread.php?tid=364275)



NULL in pawn, undefined strtok - SEnergy - 30.07.2012

pawn Код:
while(str != NULL)
error 017: undefined symbol "NULL"

pawn Код:
idx = strtok(cmdtext, " ");
error 017: undefined symbol "strtok"


Re: NULL in pawn, undefined strtok - SomebodyAndMe - 30.07.2012

strcmp..


Re: NULL in pawn, undefined strtok - SEnergy - 30.07.2012

Quote:
Originally Posted by SomebodyAndMe
Посмотреть сообщение
strcmp..
strcmp compares strings, I have to split string into tokens


Re: NULL in pawn, undefined strtok - SomebodyAndMe - 30.07.2012

You can't use a string as an array, you have to do something like #define blabla "NULL".

Look at the wiki. https://sampwiki.blast.hk/wiki/Strtok

pawn Код:
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;
}



Re: NULL in pawn, undefined strtok - Sinner - 30.07.2012

pawn Код:
#define NULL ('\0')



Re: NULL in pawn, undefined strtok - Jochemd - 30.07.2012

Don't use strcmp + strtok...

Use ZCMD + sscanf


Re: NULL in pawn, undefined strtok - SEnergy - 30.07.2012

Quote:
Originally Posted by Sinner
Посмотреть сообщение
pawn Код:
#define NULL ('\0')
didnt know that I have to declare my own NULL in pawn O_o thanks!

Quote:
Originally Posted by Jochemd
Посмотреть сообщение
Don't use strcmp + strtok...

Use ZCMD + sscanf
I've never ever used those before :X but I guess I'll have to


Re: NULL in pawn, undefined strtok - xDeadlyBoy - 30.07.2012

you can try this instead of using null, which isn't defined in pawn:
pawn Код:
while(strlen(str))



Re: NULL in pawn, undefined strtok - Jochemd - 30.07.2012

Quote:
Originally Posted by xDeadlyBoy
Посмотреть сообщение
you can try this instead of using null, which isn't defined in pawn:
pawn Код:
while(strlen(str))
If you want a server forever hanging, you should use that...