Archived

This topic is now archived and is closed to further replies.

Differences between strings in VC5 and 6

This topic is 5774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites