- Why would null termination even matter in this case? You should still get something.
- Why are you testing to see if the first array element in memsource is 0 on line 15? Is this going to be a "Don't output the file" condition? By the way you are testing an element in a char array against an 'int' they will never be equal IIRC.
I think you are getting ahead of your self, simplify the code. When you get it working at a lower level then implement what you are trying to do one step at a time.