SA-MP Forums Archive
array sizes do not match? - 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: array sizes do not match? (/showthread.php?tid=182924)



array sizes do not match? - DayDay[NE-RP] - 13.10.2010

Well i get these 2 errors when compiling,

pawn Код:
array sizes do not match, or destination array is too small
 array sizes do not match, or destination array is too small
And these are both the lines i use
pawn Код:
tmp = strtok(params, index);

    tmp2 = strtok(params, index);
You know whats wrong? or maybe can help me?


Re: array sizes do not match? - Retardedwolf - 13.10.2010

index is too small? did you do something like this? new index[1]; ? Make it bigger. (I'm guessing)


Re: array sizes do not match? - DayDay[NE-RP] - 13.10.2010

Quote:
Originally Posted by Retardedwolf
Посмотреть сообщение
index is too small? did you do something like this? new index[1]; ? Make it bigger. (I'm guessing)
This is what i got.

pawn Код:
new tmp[30],
        tmp2[30],
        index;



Re: array sizes do not match? - Lenny the Cup - 13.10.2010

tmp and tmp2 need to be bigger, I don't know what the limit for strtok is but it has a lowest one


Re: array sizes do not match? - DayDay[NE-RP] - 13.10.2010

Quote:
Originally Posted by Lenny the Cup
Посмотреть сообщение
tmp and tmp2 need to be bigger, I don't know what the limit for strtok is but it has a lowest one
tried changing the limit, still get the same error. :/


Re: array sizes do not match? - Simon - 13.10.2010

strtok returns a string of a fixed size. You get the error because strtok is returning a string bigger than 30 cells long, it's like trying to put an airplane in your garage designed to hold only your car. It just won't work, there's not enough space.

If you increase the size of tmp and tmp2 to a size bigger than or the same size as the array returned in strtok (look at the function code, try search for the array named 'result') then that will get rid of your error. I cannot tell you the exact number because it changes from script to script... some numbers if you can't find the right size are 128 and 256.

I would recommend ditching strtok and using sscanf. It's faster, won't cry about array sizes and is a lot more flexible.


Re: array sizes do not match? - DayDay[NE-RP] - 13.10.2010

Fixed itby making the size of the tmp, tmp2, to 480.

Thanks.