Skip to main content
GameDev.net gamedev.net
🔒 Locked

Copy data array

Started by programering Feb 28, 2003 at 4:13 AM 0 replies 300+ views
Original Post
programering
programering
How do I copy a array to an other array? struct human_data *humans; humans = (struct human_data *) malloc(sizeof(struct human_data)*4); struct human_data *people; memcpy(humans,people); memset(...); // ????? How do memcpy() and memset() work, what''s their parameters? witch method shall I take to copy arrays? And then, what header file shall I #include? Anton Karlsson Klingis Entertainment Games with silly humor
CoiN
CoiN
Lo,

memset() works by filling a chunk of memory with a char sent in the params.

e.g.


    
struct test_struct
{
// whatever variables here

}

// THIS WOULD GO IN main()

test_struct test;

memset(&test, 0, sizeof(test));



Would fill the struct test with 0 basically clearing the structure of all data.

memcpy() is used to copy a chunk of memory from one structure, array, variable, etc, etc, to another.

e.g.



  
test_struct test1;
test_struct test2;

// Fill test1 with something


memcpy(&test2, &test1, sizeof(test1));


So now whatever was in test1 is now in test2.

If the items you are copying from/to are not the same sizes/types then it could cause problems.

Cya...

Coin



[edited by - CoiN on February 28, 2003 8:47:48 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.