24.12.2013, 11:50
I do use packed strings and I had to reset the string for something I was making. I tried to use EOS ('\0') but it seems that it doesn't make the packed string NULL.
I run this code (here: http://slice-vps.nl:7070/#):
The output was:
I then used:
And the output was:
It is NULL like I wanted to but is it the correct way of resseting a packed string?
I run this code (here: http://slice-vps.nl:7070/#):
pawn Код:
#include <a_samp>
#if !defined isnull
#define isnull(%1) \
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
static stock
Player_Name[MAX_PLAYERS][MAX_PLAYER_NAME char];
main()
{
strpack(Player_Name[0], "Konstantinos", MAX_PLAYER_NAME);
SetTimer("PrintName", 1000, false);
}
forward PrintName();
public PrintName()
{
new
sz_T[MAX_PLAYER_NAME];
strunpack(sz_T, Player_Name[0], MAX_PLAYER_NAME);
printf("Player_Name: \"%s\" -> %s", sz_T, (isnull(sz_T)) ? ("NULL") : ("NOT NULL"));
Player_Name[0]{0} = EOS;
SetTimer("PrintName2", 1000, false);
}
forward PrintName2();
public PrintName2()
{
new
sz_T[MAX_PLAYER_NAME];
strunpack(sz_T, Player_Name[0], MAX_PLAYER_NAME);
printf("Player_Name: \"%s\" -> %s", sz_T, (isnull(sz_T)) ? ("NULL") : ("NOT NULL"));
}
pawn Код:
Player_Name: "Konstantinos" -> NOT NULL
Player_Name: "sts" -> NOT NULL
pawn Код:
#include <a_samp>
#if !defined isnull
#define isnull(%1) \
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
static stock
Player_Name[MAX_PLAYERS][MAX_PLAYER_NAME char];
main()
{
strpack(Player_Name[0], "Konstantinos", MAX_PLAYER_NAME);
SetTimer("PrintName", 1000, false);
}
forward PrintName();
public PrintName()
{
new
sz_T[MAX_PLAYER_NAME];
strunpack(sz_T, Player_Name[0], MAX_PLAYER_NAME);
printf("Player_Name: \"%s\" -> %s", sz_T, (isnull(sz_T)) ? ("NULL") : ("NOT NULL"));
strpack(Player_Name[0], "\0", MAX_PLAYER_NAME);
SetTimer("PrintName2", 1000, false);
}
forward PrintName2();
public PrintName2()
{
new
sz_T[MAX_PLAYER_NAME];
strunpack(sz_T, Player_Name[0], MAX_PLAYER_NAME);
printf("Player_Name: \"%s\" -> %s", sz_T, (isnull(sz_T)) ? ("NULL") : ("NOT NULL"));
}
pawn Код:
Player_Name: "Konstantinos" -> NOT NULL
Player_Name: "" -> NULL