SA-MP Forums Archive
[Error]"Array sizes do not match, or destination array is too small" - 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: [Error]"Array sizes do not match, or destination array is too small" (/showthread.php?tid=109349)



[Error]"Array sizes do not match, or destination array is too small" - DeathOnaStick - 19.11.2009

Hey.

I just have got the problem of following error:

Код:
....(126) : error 047: array sizes do not match, or destination array is too small
....(131) : error 047: array sizes do not match, or destination array is too small
Here the Lines making problems:

pawn Код:
new cmd[128], idx;
    cmd = strtok(cmdtext, idx);

    if (strcmp("/dkick", cmd, true, 10) == 0)
    {
    new tmp[10];
    tmp = strtok(cmdtext, idx);
    //etc......
    }
I thought it would be a problem with strtok, but i'm unsure . Does anyone have a sollution for that?

Here my strtok code:

pawn Код:
stock strtok(const string[], &index,seperator=' ')
{
    new length = strlen(string);
    new offset = index;
    new result[MAX_STRING];
    while ((index < length) && (string[index] != seperator) && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }

    result[index - offset] = EOS;
    if ((index < length) && (string[index] == seperator))
    {
        index++;
    }
    return result;
}
Thanks.


Re: [Error]"Array sizes do not match, or destination array is too small" - LarzI - 19.11.2009

tmp must be size 128, not 10 :P
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;
}
Use this version of strtok


Re: [Error]"Array sizes do not match, or destination array is too small" - yom - 19.11.2009

Instead of solving those errors, just don't use strtok, there are tons of better ways of getting a comand parameter, such as sscanf.


Re: [Error]"Array sizes do not match, or destination array is too small" - DeathOnaStick - 19.11.2009

Quote:
Originally Posted by lrZ^ aka LarzI
tmp must be size 128, not 10 :P
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;
}
Use this version of strtok
That's not the problem. The size just doesnt give error, if you have 255 minimum. But thanks anyway, i'm gonna try sscanf.


Re: [Error]"Array sizes do not match, or destination array is too small" - Oxside - 19.11.2009

use dcmd with sccanf


Re: [Error]"Array sizes do not match, or destination array is too small" - LarzI - 19.11.2009

good desicion (Y)