Alright! Fixed!
The answer was the null-terminator at the end. It turns out that when I created the char * pointer, the program was assigning garbage from the heap?, or from somewhere, and continued assigning garbage until it ran into its own '\0.' In any case, assigning a null pointer to the end of the char * fixed the problem!
In short: If you're getting a character pointer array that is longer than you expect it...
User Profile
Collapse
-
Hmmm. I had read something about 'null-terminated,' but hadn't made the connection. I'll add that to my code and see what happens.
@oler1s: I actually did use strlen because I didn't want to actually count the number of characters that showed up. I first noticed the problem when I output the character sequence to the command prompt and got a bunch of garbage on the end of what I expected.
As an additional note,...Leave a comment:
-
C++ (char *) initialization issues
I've been trying to ignore this issue for a while now, but I've come to the point in my code where I can't do so anymore. (For those of you who are wondering, this is NOT a homework question).
Platform: VC++ 2002
System: Windows XP, sp3
::First, here's the code in question::
Code:char * cSection (const char* data, int start, int finish) { if (start >= 0 && finish >=
No activity results to display
Show More
Leave a comment: