First off: Are you sure you want to return an address of a local variable from function1()? There's no guarentee that array2 will point to a meaningful block of memory when the function returns.
Secondly: Are you sure your program is valid C? I'm not an expert on C anymore but declaring variables after non declaring statements was a complete no-no in C89. array2 and pointer1 are the variables I'm looking at in particular.
Thirdly: You've got loads of redundant copying and memsetting going on so it's a bit hard to see what you're actually intending to do. For example:
memset( pointer1, 0x00, sizeof(temp) +1);
memcpy (pointer1, temp, sizeof(temp) );
could be replaced with:
memcpy ( pointer1, temp, sizeof temp );
pointer1[ sizeof temp] = 0x00;
Fourthly: In C you don't need to cast the return value of malloc. void * is compatible with any pointer type.
Fifthly: Whenever an experienced C programmer sees sizeof( x ) they start looking for a type called x. Leave off the braces when taking the size of an object.
Sixth: What's the point of pointer1? It seems totally redundant.
If all you want to is dynamically create a lump of memory and copy two other arrays into it you can do it in about three lines:
- allocate the memory
- copy the first array into the allocated memory
- copy the second array into the allocated memory after the first array
Cheers,
Ash