Advertisement

Differences between strings in VC5 and 6

Started by February 21, 2002 07:01 PM
4 comments, last by Terr 22 years, 9 months ago
Does anybody knows why this crashes my program in VC6? It worked in VC5. char *test3="This is test number 2"; test3[21]='3'; It's for replacing a character in a string. Edited by - Terr on February 21, 2002 8:03:27 PM
"Control the media, control the mind"
Hmm, maybe because your changing the ''\0'' to ''3'', remember your index''s start at 0 not 1, so the last index is 20.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
Advertisement
Maybe i''ve miscount here, it''s a example, but even if I want to change the second letter or so, it crashes
"Control the media, control the mind"
You''re editing a constant string in memory, in VC5 it must of not checked if it''s constant. If the change the code to for example

char SomeString[] = "Some text";

It should work, and here''s why, instead of allocating a static area of memory that can''t be edited then assign a pointer to it, the compiler tells the program to allocate an array like normal then fills it with the text given, which allows you to edit it.
Well then id just say its another problem with the compiler then, but still if your going to use pointers allocate some memory before assigning them a value!
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
thnx xDS4Lx and Omalacon, the char SomeString[] was the solution. And you''re right, I should allocate the memory first, but these are a just a few tests with string manipulation, memory management will come later
"Control the media, control the mind"

This topic is closed to new replies.

Advertisement