cout << buffer -- buffer needs to be a null-terminated character array. when you defined buffer you did not initialize it to anything, that means it contains random characters and the buffer may or may not contain a null-terminating 0. So cout just keeps displaying characters searching all memory for the first 0, which may be considerably beyond the end of the buffer.
To avoid that problem, declare buffer like this
That will fill the buffer with all 0s.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Online 21,953 posts
since Aug 2005