SA-MP Forums Archive
Strlib Warning - 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)
+--- Thread: Strlib Warning (/showthread.php?tid=574005)



Strlib Warning - bgedition - 12.05.2015

Hello!

When I use "strreplace" from strlib and It geves me 1 warning:
Код:
warning 224: indeterminate array size in "sizeof" expression (symbol "maxlenigh")
Can anyone help, please?
BGEdition


Re: Strlib Warning - Konstantinos - 12.05.2015

I assume it's an array from a function without a size so you get the warning. Use strlen instead of sizeof.


Re: Strlib Warning - bgedition - 12.05.2015

Now Pawno Compiler crashes


Re: Strlib Warning - Konstantinos - 12.05.2015

I don't know what's the code and where it's used so unless you post a part of it - I cannot do anything.
Another option would be to post to the thread of that strlib include so the author can fix it (if it happens to other members too).


Re: Strlib Warning - bgedition - 12.05.2015

There is my code, I don't know what is the problem:
Код:
stock GetTimeStamp(form[]) {
	new hour, minute, second, Hour[5], Minute[5], Second[5], AmPm[5];
	gettime(hour, minute, second);
	if(strfind(form, "tt", false) != -1) format(AmPm, sizeof(AmPm), "%s", (hour >= 12) ? ("PM") : ("AM")),
	hour = (hour > 12) ? (hour - 12) : (hour), strreplace(form, "tt", AmPm, true);
	if(strfind(form, "hh", true) != -1) format(Hour, sizeof(Hour), "%02d", hour), strreplace(form, "hh", Hour, true);
	else if(strfind(form, "h", true) != -1) format(Hour, sizeof(Hour), "%d", hour), strreplace(form, "h", Hour, true);
	if(strfind(form, "mm", true) != -1) format(Minute, sizeof(Minute), "%02d", minute), strreplace(form, "mm", Minute, true);
	else if(strfind(form, "m", true) != -1) format(Minute, sizeof(Minute), "%d", minute), strreplace(form, "m", Minute, true);
	if(strfind(form, "ss", true) != -1) format(Second, sizeof(Second), "%02d", second), strreplace(form, "ss", Second, true);
	else if(strfind(form, "s", true) != -1) format(Second, sizeof(Second), "%d", second), strreplace(form, "s", Second, true); 
	return form;
}



Re: Strlib Warning - Konstantinos - 12.05.2015

Don't use "form" but declare a new string and use this instead in strreplace. It'll fix your problem.


Re: Strlib Warning - bgedition - 12.05.2015

I can't understand you. Can you explain more, please?

EDIT:
I want this function to return the requested form. Example:
If form = hh:mm: ss tt, then the result should be - 04:45:09 PM


Re: Strlib Warning - Konstantinos - 12.05.2015

EDIT: Okay, it needed to add + 1 to the length of "form" and forgot to copy to form2 while testing it.

PHP код:
GetTimeStamp(form[])
{
    new 
form2[16], hourminutesecondHour[5], Minute[5], Second[5], AmPm[5];
    
gettime(hourminutesecond);
    
strcat(form2formstrlen(form) + 1);
    if(
strfind(form"tt"false) != -1format(AmPmsizeof(AmPm), "%s", (hour >= 12) ? ("PM") : ("AM")),
    
hour = (hour 12) ? (hour 12) : (hour), strreplace(form2"tt"AmPmtrue);
    if(
strfind(form"hh"true) != -1format(Hoursizeof(Hour), "%02d"hour), strreplace(form2"hh"Hourtrue);
    else if(
strfind(form"h"true) != -1format(Hoursizeof(Hour), "%d"hour), strreplace(form2"h"Hourtrue);
    if(
strfind(form"mm"true) != -1format(Minutesizeof(Minute), "%02d"minute), strreplace(form2"mm"Minutetrue);
    else if(
strfind(form"m"true) != -1format(Minutesizeof(Minute), "%d"minute), strreplace(form2"m"Minutetrue);
    if(
strfind(form"ss"true) != -1format(Secondsizeof(Second), "%02d"second), strreplace(form2"ss"Secondtrue);
    else if(
strfind(form"s"true) != -1format(Secondsizeof(Second), "%d"second), strreplace(form2"s"Secondtrue);
    return 
form2;

PHP код:
print(GetTimeStamp("hh:mm:ss tt")); 
PHP код:
// Output:
04:57:03 PM 
EDIT 2: Yeah, I get weird results with "h:m tt" - I'll check it again and reply back.


Re: Strlib Warning - bgedition - 12.05.2015

Me too, when I use my test cmd it works not good but works.
form = hh:mm: ss tt It returns me 04:59:34 PM -- That is good
but if form = h:m: s tt It returns me 4:5934P59
somewhere is something wrong with those formats but I don't know wat

EDIT:
try to use this form - h:m: s tt

EDIT 2:
Problem:
because of that the function is searching for all "m" in the string and is replacing it with minute. Pm and Am also have "m"
How to make it to search only for these first 2 or 1 "m"? I'm remembering for one decision with ignorecase to be false but I want to search it with capital letters, too.


Re: Strlib Warning - Konstantinos - 12.05.2015

Sorry to have kept you waiting.

I tested it and it seems to be working just fine:
PHP код:
stock GetTimeStamp(form[])
{
    new 
form2[16], hourhour2minutesecondHour[5], Minute[5], Second[5], AmPm[5];
    
gettime(hourminutesecond);
    
strcat(form2formsizeof (form2));
    
hour2 = (hour 12) ? (hour 12) : (hour);
    if(
strfind(form"hh"true) != -1format(Hoursizeof(Hour), "%02d"hour2), strreplace(form2"hh"Hourtrue);
    else if(
strfind(form"h"true) != -1format(Hoursizeof(Hour), "%d"hour2), strreplace(form2"h"Hourtrue);
    if(
strfind(form"mm"true) != -1format(Minutesizeof(Minute), "%02d"minute), strreplace(form2"mm"Minutetrue);
    else if(
strfind(form"m"true) != -1format(Minutesizeof(Minute), "%d"minute), strreplace(form2"m"Minutetrue);
    if(
strfind(form"ss"true) != -1format(Secondsizeof(Second), "%02d"second), strreplace(form2"ss"Secondtrue);
    else if(
strfind(form"s"true) != -1format(Secondsizeof(Second), "%d"second), strreplace(form2"s"Secondtrue);
    if(
strfind(form"tt"false) != -1format(AmPmsizeof(AmPm), "%s", (hour >= 12) ? ("PM") : ("AM")), strreplace(form2"tt"AmPmtrue);
    return 
form2;