SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 18/05/2013, 09:31 PM   #21
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,317
Reputation: 3191
Default Re: "stringh.inc": Implementing useful functions from C's "string.h"

Your strcpy is even worse than the one in the first post!
Y_Less is offline   Reply With Quote
Old 18/05/2013, 09:43 PM   #22
BigETI
High-roller
 
BigETI's Avatar
 
Join Date: Mar 2010
Location: Germany
Posts: 1,051
Reputation: 345
Default AW: "stringh.inc": Implementing useful functions from C's "string.h"

What's wrong with NULL terminating a string and use strcat to make it look like strcpy. I've actually tested this macro...

Edit:
pawn Code:
new buffer[128] = "";
__strcat_(buffer, "Test __strcat_");
print(buffer);
strncat(buffer, "Test strncat", 12);
print(buffer);
printf("First 's' at %d", strchr(buffer, 's'));
printf("Last 's' at %d", strrchr(buffer, 's'));
printf("__strcmp_ result: %d", __strcmp_("foo", "Foo"));
printf("strncmp result: %d", strncmp("foo", "Foo", 2));
printf("strcasecmp result: %d", strcmp("foo", "Foo"));
printf("strncasecmp result: %d", strncasecmp("foo", "Foo", 2));
strcpy(buffer, "Test strcpy");
print(buffer);
strncpy(buffer, "Test strncpy", 12);
print(buffer);
print(strpbrk(buffer, {'s', 't', 'c'}));
printf("strspn %d", strspn(buffer, {'s', 't', 'c'}));
printf("strspn %d", strcspn(buffer, {'s', 't', 'c'}));
printf("strstr %d", strstr(buffer, "Test"));
printf("strcasestr %d", strstr(buffer, "Test"));

Code:
[22:45:40] Test __strcat_
[22:45:40] Test strncat
[22:45:40] First 's' at 3
[22:45:40] Last 's' at 6
[22:45:40] __strcmp_ result: 1
[22:45:40] strncmp result: 1
[22:45:40] strcasecmp result: 1
[22:45:40] strncasecmp result: 0
[22:45:40] Test strcpy
[22:45:40] Test strncpy
[22:45:40] ssttcssttrsspn 
[22:45:40] strspn 9
[22:45:40] strspn 3
[22:45:40] strstr 0
[22:45:40] strcasestr 0
BigETI is offline   Reply With Quote
Old 18/05/2013, 10:44 PM   #23
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,317
Reputation: 3191
Default Re: "stringh.inc": Implementing useful functions from C's "string.h"

That's not the problem, the "sizeof" is.
Y_Less is offline   Reply With Quote
Old 18/05/2013, 10:55 PM   #24
BigETI
High-roller
 
BigETI's Avatar
 
Join Date: Mar 2010
Location: Germany
Posts: 1,051
Reputation: 345
Default AW: "stringh.inc": Implementing useful functions from C's "string.h"

pawn Code:
#define strcpy(%0,%1)           strcat((%0[0]='\0',%0),%1,_)

It's the same as you would use "sizeof"


or...
pawn Code:
#define strcpy(%0,%1)           strcat((%0[0]='\0',%0),%1,strlen(%1))
?
BigETI is offline   Reply With Quote
Old 18/05/2013, 11:11 PM   #25
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,317
Reputation: 3191
Default Re: "stringh.inc": Implementing useful functions from C's "string.h"

a) You don't need it because "sizeof" is already the default for that parameter.

b) There are some cases where sizeof doesn't work (mainly enums) and your code offers no alternative. Conversely, the code in the first post REQUIRES the final parameter rather than making it optional.
Y_Less is offline   Reply With Quote
Old 18/05/2013, 11:35 PM   #26
BigETI
High-roller
 
BigETI's Avatar
 
Join Date: Mar 2010
Location: Germany
Posts: 1,051
Reputation: 345
Default AW: "stringh.inc": Implementing useful functions from C's "string.h"

Well, then as you said
pawn Code:
#define strcpy(%0,%1)           strcat((%0[0]='\0',%0),%1)
should allow to make this parameter optional for the user.
In the first place I thought to restrict the optional arguments at the strcpy macro for the user, so it becomes more likely the one used in C/C++. But as you said before it uses to have conflicts with enums and etc. Thanks for the info.
BigETI is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error 001: expected token: "-string end-", but found "-identifier-" iGetty Scripting Help 4 15/05/2012 06:39 PM
5 Dialog errors - Input line too long, undefined symbol "t","is" and "only" Deal-or-die Scripting Help 6 01/05/2012 01:08 PM
error 001: expected token: "-string end-", but found "-identifier-" Any Ideas? Jack_Rocker Scripting Help 5 04/11/2011 02:03 PM


All times are GMT. The time now is 07:26 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.