04.07.2020, 12:34
(
Last edited by MarianImmortalGod; 04/07/2020 at 07:09 PM.
)
Quote:
This is the case for all strings (unless if you're using the dynamic memory plugin).
Strings (arrays) are basically just a bunch of variables. PAWN reads these arrays as strings. All string functions (reading strings, strings such as strcmp(), strlen()) use the null terminator (aka EOS aka \0) to find the end of the string. So if you have the text "hello", the array needs the size of the string (in this case 5) + 1 cell (one cell is one index / memory space of the array) for the null terminator. This is what "hello" would look like: pawn Code:
pawn Code:
You don't have to define the array size of the array has a default value/input. For example: pawn Code:
And that's why you include one more cell than the size of the array. It is not y_va specific. |
This is how i do a format message that i need something to show like a number or a name.
Code:
new string[9], test = 0; format(string, sizeof(string), "Hello %d", test); SendClientMessage(playerid, -1, string);
The reason why i ask is because i don't need to count every single char, and i don't want to use EOS.
Normal format:
Code:
new string[9], test = 0; format(string, sizeof(string), "Hello %d", test); SendClientMessage(playerid, -1, string);
Code:
new test = 0; va_SendClientMessage(playerid, -1, "Hello %d", test);
And the question about everything is, it is how EOS works to end the character count string at the end or it keeps counting until MAX_STRING and ruin my host CPU MEM ?
Edit: imagine using
Code:
new string[MAX_STRING]; // GLOBAL new test = 0; string[0] = (EOS); format(string, sizeof(string), "Hello %d", test); SendClientMessage(playerid, -1, string);
Code:
new test = 0; va_SendClientMessage(playerid, -1, "Hello %d", test);