Strings doesn't work in enums
#1

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

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

Quote:
Originally Posted by Vince
View Post
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)