"CoL" <> writes:
> In this case , according to ANSI C standard the string literal becomes
> the part of read only memory, most obvious the datasection. So the
> nature of the char * str actually becomes const char *str1... so you
> cant write into it.
One more time. Please provide context when you post a followup.
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
Please complain to Google about their broken interface.
String literals in C are not of type const char*. A string literal is
an array of char (not const); in most contexts, it's implicitly
converted to char* (again, not const). Modifying a string literal is
undefined behavior because the standard specifically says it's
undefined behavior.
It might have made more sense for string literals to be const
(<OT>they are in C++</OT>), but they aren't.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.