If an input const string is being modified in some way (which is resulting in C compiler warning), what is the best way to handle it - typecasting it to a new variable and then using it OR duplicating it and using it and then freeing it. Or is there any other way to handle this type of scenario. please suggest. Any help would be appreciated.
//Typecasting
const char * s1;
char * s2 = (char *)s1;
//Duplicate and free
const char * s1;
char * s2 = strdup( s1 );
free(s2)
EDIT: It is a C compiler; not C++. I am not sure whether in typecasting, s2 will be a new copy of string s1 or will it be pointing to the original string s1?
Thanks for the answers. I have one more doubt-
const char * c1;
const char * c2 = c1;
Is the above assignment valid?