[Tutorial] Packed strings in PAWN
#9

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/#):
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"));
}
The output was:
pawn Код:
Player_Name: "Konstantinos" -> NOT NULL
Player_Name: "sts" -> NOT NULL
I then used:
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"));
}
And the output was:
pawn Код:
Player_Name: "Konstantinos" -> NOT NULL
Player_Name: "" -> NULL
It is NULL like I wanted to but is it the correct way of resseting a packed string?
Reply


Messages In This Thread
Packed strings in PAWN - by Emmet_ - 11.12.2013, 12:19
Re: Packed strings in PAWN - by Hansrutger - 11.12.2013, 13:14
Re: Packed strings in PAWN - by Emmet_ - 11.12.2013, 13:48
Re: Packed strings in PAWN - by Emmet_ - 11.12.2013, 13:59
Re: Packed strings in PAWN - by Emmet_ - 11.12.2013, 14:12
AW: Packed strings in PAWN - by BigETI - 12.12.2013, 07:41
Re: Packed strings in PAWN - by Emmet_ - 12.12.2013, 11:08
Respuesta: Packed strings in PAWN - by Swedky - 17.12.2013, 04:28
Re: Packed strings in PAWN - by Konstantinos - 24.12.2013, 11:50
Re: Packed strings in PAWN - by newbienoob - 24.12.2013, 13:15

Forum Jump:


Users browsing this thread: 2 Guest(s)