SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 13/10/2018, 10:42 PM   #1
SapMan
Banned
 
Join Date: Jul 2017
Posts: 142
Reputation: 12
Default warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")

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")
SapMan is offline   Reply With Quote
Old 14/10/2018, 01:08 AM   #2
Graber
Banned
 
Join Date: Mar 2013
Location: Germany
Posts: 108
Reputation: 147
Default Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")

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.
Graber is offline   Reply With Quote
Old 14/10/2018, 02:50 AM   #3
SapMan
Banned
 
Join Date: Jul 2017
Posts: 142
Reputation: 12
Default Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")

So, how can I solve it?
SapMan is offline   Reply With Quote
Old 14/10/2018, 04:13 AM   #4
khRamin78
Huge Clucker
 
Join Date: Jun 2015
Posts: 301
Reputation: 28
Default Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")

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

strlen(string)

instead of

sizeof(string)
khRamin78 is offline   Reply With Quote
Old 14/10/2018, 03:23 PM   #5
SapMan
Banned
 
Join Date: Jul 2017
Posts: 142
Reputation: 12
Default Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")

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;

SapMan is offline   Reply With Quote
Old 14/10/2018, 03:55 PM   #6
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,626
Reputation: 535
Default Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")

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).
NaS is online now   Reply With Quote
Old 14/10/2018, 06:09 PM   #7
SapMan
Banned
 
Join Date: Jul 2017
Posts: 142
Reputation: 12
Default Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")

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.
SapMan is offline   Reply With Quote
Old 14/10/2018, 06:12 PM   #8
SapMan
Banned
 
Join Date: Jul 2017
Posts: 142
Reputation: 12
Default Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")

Is there a solution that works?
SapMan is offline   Reply With Quote
Old 14/10/2018, 07:20 PM   #9
SapMan
Banned
 
Join Date: Jul 2017
Posts: 142
Reputation: 12
Default Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")

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.
SapMan is offline   Reply With Quote
Old 14/10/2018, 09:05 PM   #10
SapMan
Banned
 
Join Date: Jul 2017
Posts: 142
Reputation: 12
Default Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")

Well, then how should it be exactly?
SapMan is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command warning (params) warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength") Riwerry Scripting Help 1 24/05/2014 10:54 PM
warning 224: indeterminate array size in "sizeof" expression (symbol "") Fierro Scripting Help 7 12/10/2013 02:59 PM
"Must be a constant expression; assumed zero","Array dimensions do not match" Fierro Scripting Help 0 08/09/2013 10:11 PM
5 Dialog errors - Input line too long, undefined symbol "t","is" and "only" Deal-or-die Scripting Help 6 01/05/2012 12:08 PM
[SOLVED]warning 224: indeterminate array size in "sizeof" expression (symbol "") LarzI Help Archive 2 22/12/2009 04:32 AM


All times are GMT. The time now is 05:57 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.