/* megacopy.c - copies structs generically through the heap YOUR NAME(S), 8/29/2012 */ #include #include struct Foo { int x; double y; }; struct Bar { char* string; struct Foo* foo; }; void printFoo( struct Foo* foo ) { printf( "Foo.x: %i\nFoo.y: %lf\n", foo->x, foo->y ); } void printBar( struct Bar* bar ) { printf( "Bar.string: %s\nBar.foo:\n", bar->string ); printFoo( bar->foo ); } // change ONLY code in megacopyHeap void* megacopyHeap( void* src, size_t size ) { return NULL; } int main() { struct Foo fooSrc = { 5, 2.5 }; struct Foo* fooDest; struct Bar barSrc = { "bar string", &fooSrc }; struct Bar* barDest; printf( "Sources:\n" ); printFoo( &fooSrc ); printBar( &barSrc ); fooDest = megacopyHeap( &fooSrc, sizeof( struct Foo ) ); barDest = megacopyHeap( &barSrc, sizeof( struct Bar ) ); printf( "\nDestinations:\n" ); printFoo( fooDest ); printBar( barDest ); free( fooDest ); free( barDest ); return 0; }