Strings doesn't work in enums - 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: Strings doesn't work in enums (
/showthread.php?tid=448784)
Strings doesn't work in enums -
Kirollos - 05.07.2013
Hello There,
I've a problem with strings inside enums.
when using functions like (strcat or cache_get_field and functions that writes in a string), the strings' always null.
only when using format() had worked. (according to what i've tested)
here is the code:
pawn Code:
enum enumz
{
str1[50],
str2[50]
};
public OnFilterScriptInit()
{
new test[enumz];
new das[50] = "HI STR1";
new das2[50] = "HI STR2";
strcat(test[str1], das); // doesn't work :x
strcat(test[str2], das2); // doesn't work :x
printf("%s || %s", das, test[str1]); // prints "HI STR1 || "
printf("%s || %s", das2, test[str2]); // prints "HI STR2 || "
printf("_______________________________");
format(test[str1], 50, "%s", das); // works
format(test[str2], 50, "%s", das2); // works
printf("%s || %s", das, test[str1]); // prints "HI STR1 || HI STR1"
printf("%s || %s", das2, test[str2]); // prints "HI STR2 || HI STR2"
}
Is there anything i've made done or it can't be done?
Thanks.
Re: Strings doesn't work in enums -
Vince - 05.07.2013
strcat has a third, optional, parameter called
maxlength which by default is set to
sizeof(dest). However, you can't get the size of an array element and thus that code is invalid. You must supply the length manually. The same applies to cache_get_field.
Re: Strings doesn't work in enums -
Kirollos - 05.07.2013
Quote:
Originally Posted by Vince
strcat has a third, optional, parameter called maxlength which by default is set to sizeof(dest). However, you can't get the size of an array element and thus that code is invalid. You must supply the length manually. The same applies to cache_get_field.
|
Oh! thats why it didn't work, anyways i tried adding a maxlength and it worked!
Thanks