in reply to Dealing with huge text string

Yeah, don't forget that “memory” is virtual. In other words, it is a disk-file. So your program tried to copy 168 megabytes from one disk file to another, the hard way. It probably never succeeded in doing just-that.

There are several ways to do it (of course), but yes, the bottom line is that you need to read n bytes at a time and write each piece out followed by a newline.