AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   memcpy() equivalent? (https://forums.alliedmods.net/showthread.php?t=174111)

Misery 12-15-2011 15:26

memcpy() equivalent?
 
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

fysiks 12-15-2011 15:35

Re: memcpy() equivalent?
 
You can just use a loop. I'm not aware of any built in function.

Xellath 12-15-2011 15:42

Re: memcpy() equivalent?
 
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 ] );     } }

Misery 12-15-2011 15:42

Re: memcpy() equivalent?
 
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.

fysiks 12-15-2011 15:45

Re: memcpy() equivalent?
 
Quote:

Originally Posted by Xellath (Post 1613762)
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.

Xellath 12-15-2011 15:48

Re: memcpy() equivalent?
 
Quote:

Originally Posted by fysiks (Post 1613766)
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.

Diegorkable 12-15-2011 17:53

Re: memcpy() equivalent?
 
Like fysiks said, just loop through all the cells and copy them.

fysiks 12-15-2011 23:18

Re: memcpy() equivalent?
 
Quote:

Originally Posted by Xellath (Post 1613769)
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.


All times are GMT -4. The time now is 11:48.

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