chris rrr
asked on
set value of a char **
char *str[2] = {"abc","xyz"};
printf("str[0] = %s, str[1] = %s\n", str[0], str[1]);
//try to change abc to aXc by setting character index;
printf("[0]:%c , [1]:%c, [2]:%c\n", str[0][0], str[0][1], str[0][2]);//before
str[0][1] = 'X';// ===> why doesn't this work
printf("[0]:%c , [1]:%c, [2]:%c\n", str[0][0], str[0][1], str[0][2]);//after
...this doesn't work ...?why?
printf("str[0] = %s, str[1] = %s\n", str[0], str[1]);
//try to change abc to aXc by setting character index;
printf("[0]:%c , [1]:%c, [2]:%c\n", str[0][0], str[0][1], str[0][2]);//before
str[0][1] = 'X';// ===> why doesn't this work
printf("[0]:%c , [1]:%c, [2]:%c\n", str[0][0], str[0][1], str[0][2]);//after
...this doesn't work ...?why?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You allow 4 spaces to fit in the terminating null \0 that represents the end of the character sequence.
>>Wondering why it works now, but would crash earlier today...
I'd guess you had string pooling switched on (/Gf) in one project and off in the other.
Paul
I'd guess you had string pooling switched on (/Gf) in one project and off in the other.
Paul
ASKER
>>I'd guess you had string pooling switched on (/Gf) in one project and off in the other.
Not unless it somehow does it automatically. The only thing differenct about the 2 projects, was some insertion of assembly code in the one that would crash. My VC++ Kept locking up on me when I opened that workspace/project. But the strange thing is that a friend of mine who brought the question to my attention, couldn't get it to work without crashing either. Well, I am going to try to figure out more, it isn't worth too much time, but it is curious.
Thanks for your response,
Chris
Not unless it somehow does it automatically. The only thing differenct about the 2 projects, was some insertion of assembly code in the one that would crash. My VC++ Kept locking up on me when I opened that workspace/project. But the strange thing is that a friend of mine who brought the question to my attention, couldn't get it to work without crashing either. Well, I am going to try to figure out more, it isn't worth too much time, but it is curious.
Thanks for your response,
Chris
ASKER
Sorry guys, I totally forgot about this.
ASKER
What the heck, I just gave the accepted answer to imladris ....I don't understand what happened. I will let community support know.
Sorry, I really made a mess of this question.
Thanks for your help guys.
Sorry, I really made a mess of this question.
Thanks for your help guys.
ASKER
Using MSVC++ 6.
then when I add your code, it doesn't replace the character.???
Wondering why it works now, but would crash earlier today...
I will look into it