Strlib Warning
#1

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

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

Now Pawno Compiler crashes
Reply
#4

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

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;
}
Reply
#6

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

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

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

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

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;

Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)