Whats the difference between strcpy and format - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Whats the difference between strcpy and format (
/showthread.php?tid=664375)
Whats the difference between strcpy and format -
NoteND - 27.02.2019
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] = EOS, dest), source, maxlength);
}
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 ?
Re: Whats the difference between strcpy and format -
RoboN1X - 27.02.2019
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
Re: Whats the difference between strcpy and format -
NoteND - 27.02.2019
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