trailing characters on newly initialized character arrays
So I'm doing some file I/O and when i initialize a character array of a given size, a bunch of nonsense characters (like ýýýýÝÝÝÝÝÝÝÝÝÝÝA) is appended IN ADDITION to all of the characters i want. Do you think it has something to do w/ the placement of the array in memory? I'm first declaring the pointer, then assigning a size a couple lines later:
char *InString;
InString = new char[FileLength];
where FileLength is an integer. It's really weird, and i've verified it w/ the debugger. Immediately when it is initialized it is given "FileLength" spaces, PLUS a few more for the nonsense characters. Any help would be GREATLY appreciated.
Re: trailing characters on newly initialized character arrays
Hi,
The ýýý... is an indication that the memory allocated by the keyword new is exceeded. You do not have to worry about that coz you will not be writing to those locations (if you are doing it correctly).
Chao
Re: trailing characters on newly initialized character arrays
Make sure u terminate the string with a null char.
Don't worry about those garbage chars.
Re: trailing characters on newly initialized character arrays
THANK YOU!!!
I didn't even think of the null char at the end of strings. The CString conversion now stops reading when it hits the null. I appreciate it.