warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")
#1

Why is this happening? I have not found any solution for this.

PHP Code:
CMD:test(playeridparams[])
{
    new 
text[90];
    if(
sscanf(params"s[90]"text)) return SendClientMessage(playerid,-1"/test (text)");
    
    
TestText(text);
    new 
str[90]; format(strsizeof(str), "%s"text);
    
SendClientMessageToAll(-1str);
    return 
1;
}
TestText(text[])
{
    
strreplace(text"test_01""replace_01");
    
strreplace(text"test_02""replace_02");
    return 
1;

PHP Code:
strreplace(string[], const search[], const replacement[], bool:ignorecase falsepos 0limit = -1maxlength sizeof(string))
{
    if(
limit == 0)
    return 
0;
    new 
sublen strlen(search),
    
replen strlen(replacement),
    
bool:packed ispacked(string),
    
maxlen maxlength,
    
len strlen(string),
    
count 0;
    if(
packed
    
maxlen *= 4;
    if(!
sublen
    return 
0;
    while(-
!= (pos strfind(stringsearchignorecasepos)))
    {
        
strdel(stringpospos sublen);
        
len -= sublen;
        if(
replen && len replen maxlen){
            
strins(stringreplacementposmaxlength);
            
pos += replen;
            
len += replen;
        }
        
        if(
limit != -&& ++count >= limit
        break;
    }
    return 
count;

warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")
Reply
#2

In the TestText function, the function is accepting an array (text[]) from any size, because of that it can't know what size the array is. When you try to use the strreplace function, the function tries to resolve the size of this array, but since the size it's unknown, it can't, and displays that warning.
Reply
#3

So, how can I solve it?
Reply
#4

Quote:
Originally Posted by SapMan
View Post
So, how can I solve it?
easly use

strlen(string)

instead of

sizeof(string)
Reply
#5

When I put it like that, it does not give me warnings. Why?

PHP Code:
TestText(text[90])
{
    
strreplace(text"test_01""replace_01");
    
strreplace(text"test_02""replace_02");
    return 
1;

Reply
#6

Quote:
Originally Posted by SapMan
View Post
When I put it like that, it does not give me warnings. Why?

PHP Code:
TestText(text[90])
{
    
strreplace(text"test_01""replace_01");
    
strreplace(text"test_02""replace_02");
    return 
1;

Because now the array size is known. Which now results in a limited max. length of the string. Just pass the size of the array as a seperate function parameter (or use this, knowing it's limited to 90 characters).
Reply
#7

When I use this in "OnPlayerText" it gives me error "error 047: array sizes do not match, or destination array is too small"

PHP Code:
public OnPlayerText(playeridtext[])
{
TestText(text);
return 
0;

I put "TestText (text [145])" and follow the error.
Reply
#8

Is there a solution that works?
Reply
#9

I have not modified it "OnPlayerText (playerid, text [])" so it is in my game mode. When I use "TestText (text);" in the callback "OnPlayerText", I throw away the error that I previously published.
Reply
#10

Well, then how should it be exactly?
Reply
#11

pawn Код:
public OnPlayerText(playerid, text[])
{
    TestText(text,strlen(text));
    return 0;
}

CMD:test(playerid, params[])
{
    new text[90];
    if(sscanf(params, "s[90]", text)) return SendClientMessage(playerid,-1, "/test (text)");
   
    TestText(text); // text is 90 so you dont need pass sizeof
    new str[90]; format(str, sizeof(str), "%s", text);
    SendClientMessageToAll(-1, str);
    return 1;
}

TestText(text[], s_size = sizeof(text))
{
    strreplace(text, "test_01", "replace_01", .maxlength = s_size);
    strreplace(text, "test_02", "replace_02", .maxlength = s_size);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)