inputtext help
#1

Hello, I've made a command, with a dialog. In the response of this dialog, it takes first 4 characters of the entered text (inputtext) and stores it in "pbInfo[pbid][pbPassword]"

When it sends me that message "you have changed the password to ...", I see it's changed to 3 characters only, not 4, why?

PHP код:
case DIALOG_PB_EDITPW:
        {
            if(
isnull(inputtext)) return ShowPlayerDialog(playeridDIALOG_PB_EDITPWDIALOG_STYLE_INPUT""COL_WHITE"Setting Paintball password"""COL_WHITE"First 4 characters are going to be the password:\n\n"COL_RED"The password must be at least 4 characters.""Select""Done");
            if(
strlen(inputtext) < 4) return ShowPlayerDialog(playeridDIALOG_PB_EDITPWDIALOG_STYLE_INPUT""COL_WHITE"Setting Paintball password"""COL_WHITE"First 4 characters are going to be the password:\n\n"COL_RED"The password must be at least 4 characters.""Select""Done");
            new 
string[128], pbid pInfo[playerid][InPBLobby], pw[4];
            
strmid(pwinputtext03);
            
pbInfo[pbid][pbPassword] = pw;
            
format(stringsizeof(string), "You have changed the lobby password to %s."pbInfo[pbid][pbPassword]);
            
NGMSG(playeridstring);
        } 
Reply
#2

The size of pw has to be 5 (4 characters + 1 NULL).

Is the reason you set only the first 4 characters as password so you can copy directly with equal sign? Better use strcpy (strcat but resetting destination) for that matter.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
The size of pw has to be 5 (4 characters + 1 NULL).

Is the reason you set only the first 4 characters as password so you can copy directly with equal sign? Better use strcpy (strcat but resetting destination) for that matter.
I'm so confused, I don't know how to use strcpy, can you help me please?
Reply
#4

Every string has +1 to it because it has NULL_Terminator,
Ex:
5=4
Reply
#5

Great, solved, thank you! +REP :P

Thank you Gotham too :P
Reply
#6

Quote:
Originally Posted by Ahmed21
Посмотреть сообщение
I'm so confused, I don't know how to use strcpy, can you help me please?
pawn Код:
#if !defined strcpy
    #define strcpy(%0,%1) strcat((%0[0] = EOS, %0), %1)
#endif
pawn Код:
// usage:
strcpy(destination[], const source[], maxlength = sizeof dest)
When you try to copy to enum-array you must specify the size yourself as sizeof wouldn't work.

pawn Код:
strcpy(pbInfo[pbid][pbPassword], pw, size_of_pbPassword);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)