Click to See Complete Forum and Search --> : trailing characters on newly initialized character arrays


Rob W.
June 1st, 1999, 06:44 PM
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.

Chao
June 1st, 1999, 09:52 PM
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

Yogen M
June 2nd, 1999, 01:30 AM
Make sure u terminate the string with a null char.
Don't worry about those garbage chars.

Rob W.
June 2nd, 1999, 09:57 AM
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.