Link to home
Start Free TrialLog in
Avatar of chris rrr
chris rrrFlag for United States of America

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?
ASKER CERTIFIED SOLUTION
Avatar of imladris
imladris
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chris rrr

ASKER

Maybe it was my project. It seemed to work fine when I made a new project and coppied my code in.
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of twobitadder
twobitadder

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.
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
Sorry guys, I totally forgot about this.
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.