[Error]"Array sizes do not match, or destination array is too small"
#1

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.
Reply
#2

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
Reply
#3

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

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.
Reply
#5

use dcmd with sccanf
Reply
#6

good desicion (Y)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)