"Debug Error! Program: C:\Users... my file path HEAP CORRUPTION DETECTED: after Normal block (#78) at 0x011058C8. CRT detected that the application wrote to memory after end of heap buffer." the code wrote past the end of a dynamically allocated memory buffer. Fix that one problem and the rest should be very easy