Raised This Month: $51 Target: $400
 12% 

memcpy() equivalent?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Misery
Senior Member
Join Date: Dec 2010
Old 12-15-2011 , 15:26   memcpy() equivalent?
Reply With Quote #1

Hi,

I'm trying currently to do something like this:
Code:
new src[] = { 1, 1, 0, 1, 2, 0, 0, 1 };
new dst[32];
// [...]
copy(lame, 8, dst);
However, the above code does not work as I want, because since copy() is a string function, itll stop at the third character in src[], taking it as the terminating char ('\0').

Any AMXX equivalent of memcpy()?

Thanks!

Misery

Last edited by Misery; 12-15-2011 at 15:26.
Misery is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-15-2011 , 15:35   Re: memcpy() equivalent?
Reply With Quote #2

You can just use a loop. I'm not aware of any built in function.
__________________
fysiks is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 12-15-2011 , 15:42   Re: memcpy() equivalent?
Reply With Quote #3

Afraid there's no equivalent of memcpy() in the AMXX toolkit.

You could do something like this however:
Code:
new Input[ ] = { 3, 1, 3, 1, 3 }; new Output[ 6 ]; memcpy( Input, Output ); // Output: "31313" memcpy( const Input[ ], Output[ ] ) {     for( new InputIndex = 0, Length = 0; InputIndex < sizeof( Input ); InputIndex++ )     {         Length += formatex( Output[ Length ], charsmax( Output ) - Length, "%i", Input[ InputIndex ] );     } }
__________________
Achievements API - a simple way for you to create your OWN custom achievements!

Last edited by Xellath; 12-15-2011 at 15:42.
Xellath is offline
Misery
Senior Member
Join Date: Dec 2010
Old 12-15-2011 , 15:42   Re: memcpy() equivalent?
Reply With Quote #4

Yes, of course I wrote a memcpy() myself, as a workaround. ^^
I was just wondering if a native version was around there, as my source is already huge...

Bah, not a big deal I guess. Still, if anyone got something interesting to say, feel free to tell me.

Last edited by Misery; 12-15-2011 at 15:43.
Misery is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-15-2011 , 15:45   Re: memcpy() equivalent?
Reply With Quote #5

Quote:
Originally Posted by Xellath View Post
Afraid there's no equivalent of memcpy() in the AMXX toolkit.

You could do something like this however:
Code:
new Input[ ] = { 3, 1, 3, 1, 3 }; new Output[ 6 ]; memcpy( Input, Output ); // Output: "31313" memcpy( const Input[ ], Output[ ] ) {     for( new InputIndex = 0, Length = 0; InputIndex < sizeof( Input ); InputIndex++ )     {         Length += formatex( Output[ Length ], charsmax( Output ) - Length, "%i", Input[ InputIndex ] );     } }
Why are you using a string? He just wants to copy memory. You are actually converting the memory to something else.
__________________

Last edited by fysiks; 12-15-2011 at 15:46.
fysiks is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 12-15-2011 , 15:48   Re: memcpy() equivalent?
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
Why are you using a string? He just wants to copy memory. You are actually converting the memory to something else.
From what I gather from the first post, it seems he wants it to be a string. I could be wrong though.
__________________
Achievements API - a simple way for you to create your OWN custom achievements!

Last edited by Xellath; 12-15-2011 at 15:49.
Xellath is offline
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 12-15-2011 , 17:53   Re: memcpy() equivalent?
Reply With Quote #7

Like fysiks said, just loop through all the cells and copy them.
__________________
My Projects:

Auto-Mix (Pug): 100%

Joined the Military (a soldier now) - Inactive
Diegorkable is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-15-2011 , 23:18   Re: memcpy() equivalent?
Reply With Quote #8

Quote:
Originally Posted by Xellath View Post
From what I gather from the first post, it seems he wants it to be a string. I could be wrong though.
No, he said that copy() is a string function and stops copying when it finds the zero-terminator. He asked to copy all values.
__________________
fysiks is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 16:59.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode