/* megacopy.c - copies structs generically through the stack YOUR NAME(S), 8/29/2012 */ #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 megacopy void megacopy( void* dest, void* src, size_t size ) { } 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 ); megacopy( &fooDest, &fooSrc, sizeof( struct Foo ) ); megacopy( &barDest, &barSrc, sizeof( struct Bar ) ); printf( "\nDestinations:\n" ); printFoo( &fooDest ); printBar( &barDest ); return 0; }