Whats the difference between strcpy and format
#1

Hey!

I'm just wondering whats the difference between these two for copying string into another string.

PHP код:
enum PlayerData
{
     
pTag[32]
}
new 
pInfo[MAX_PLAYERS][PlayerData
PHP код:
stock strcpy(dest[], const source[], maxlength=sizeof dest)
{
    
strcat((dest[0] = EOSdest), sourcemaxlength);
}
strcpy(pInfo[playerid][pTag], "Something"sizeof(pInfo[playerid][pTag])); 
or using..

PHP код:
format(pInfo[playerid][pTag], sizeof(pInfo[playerid][pTag], "Something"); 
Which is better and why ?
Reply
#2

The way you use sizeof(pInfo[playerid][pTag]) seems wrong, i doubt it will even compile, you'd need to put a #define MAX_TAG_LEN 32 in place of pTag size and use it as well in functions that need the pTag size.
Код:
#define MAX_TAG_LEN 32
enum PlayerData
{
     pTag[MAX_TAG_LEN]
}


strcpy(pInfo[playerid][pTag], "Something", MAX_TAG_LEN);
I would never use format() without need to change the "format" in the string itself (i.e. not using the arguments in place of %)


You can read the "Copying string" section on https://sampforum.blast.hk/showthread.php?pid=3517039#pid3517039
Reply
#3

Quote:
Originally Posted by RoboN1X
Посмотреть сообщение
The way you use sizeof(pInfo[playerid][pTag]) seems wrong, i doubt it will even compile, you'd need to put a #define MAX_TAG_LEN 32 in place of pTag size and use it as well in functions that need the pTag size.
Код:
#define MAX_TAG_LEN 32
enum PlayerData
{
     pTag[MAX_TAG_LEN]
}


strcpy(pInfo[playerid][pTag], "Something", MAX_TAG_LEN);
I would never use format() without need to change the "format" in the string itself (i.e. not using the arguments in place of %)


You can read the "Copying string" section on https://sampforum.blast.hk/showthread.php?pid=3517039#pid3517039
wtf reply xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)