warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength") -
SapMan - 13.10.2018
Why is this happening? I have not found any solution for this.
PHP Code:
CMD:test(playerid, params[])
{
new text[90];
if(sscanf(params, "s[90]", text)) return SendClientMessage(playerid,-1, "/test (text)");
TestText(text);
new str[90]; format(str, sizeof(str), "%s", text);
SendClientMessageToAll(-1, str);
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 = false, pos = 0, limit = -1, maxlength = 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(-1 != (pos = strfind(string, search, ignorecase, pos)))
{
strdel(string, pos, pos + sublen);
len -= sublen;
if(replen && len + replen < maxlen){
strins(string, replacement, pos, maxlength);
pos += replen;
len += replen;
}
if(limit != -1 && ++count >= limit)
break;
}
return count;
}
warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")
Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength") -
Graber - 14.10.2018
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.
Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength") -
SapMan - 14.10.2018
So, how can I solve it?
Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength") -
khRamin78 - 14.10.2018
Quote:
Originally Posted by SapMan
So, how can I solve it?
|
easly use
strlen(string)
instead of
sizeof(string)
Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength") -
SapMan - 14.10.2018
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;
}
Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength") -
NaS - 14.10.2018
Quote:
Originally Posted by SapMan
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).
Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength") -
SapMan - 14.10.2018
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(playerid, text[])
{
TestText(text);
return 0;
}
I put "TestText (text [145])" and follow the error.
Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength") -
SapMan - 14.10.2018
Is there a solution that works?
Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength") -
SapMan - 14.10.2018
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.
Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength") -
SapMan - 14.10.2018
Well, then how should it be exactly?
Re: warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength") -
Jefff - 14.10.2018
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;
}