Resolved infinite loop/segfault in struct-writing fuctnion.
Added newline at end to fix EOF error.
Added code from Naman.