Re: Help!!! Out of Memory!!!
A NULL terminated string (also called an ASCIIZ string) must have room for the characters *and* the '\0' value. Unlike Pascal or some other languages, in C or C++, the '\0' character determines the end of an array of characters. So if you have a string that is 10 characters, actually it is 11 characters because of the terminating '\0' value.
What you did is that you overwrote memory. You only allocated "length" characters, but you called strcpy(), which copies the source string (which is "length" characters in your example), *plus* the terminating NULL. The overwrite occurred because of the NULL being written in a location that wasn't allocated.
The bottom line is that just being off by one byte can cause a program to crash.
Regards,
Paul McKenzie