Differences between strings in VC5 and 6
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
Hmm, maybe because your changing the ''\0'' to ''3'', remember your index''s start at 0 not 1, so the last index is 20.
Maybe i''ve miscount here, it''s a example, but even if I want to change the second letter or so, it crashes
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.
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!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement