|
-
Oct 17th, 2002, 02:47 PM
#1
Thread Starter
Addicted Member
const char* to char*
How do you convert a variable of type 'const char*' to 'char*'?
To protect time is to protect everything...
-
Oct 17th, 2002, 03:51 PM
#2
Frenzied Member
You don't really - here's why
Accesible memory is either read-only or read/write. You cannot change memory the compiler designated as read-only to be read/write.
const means read-only
try moving the data do a different place in memory that is read/write like:
Code:
const char *s="hi there";
char tmp[20];
strcpy(tmp,s);
// tmp is read/write
-
Oct 17th, 2002, 04:42 PM
#3
Generic way:
const char *str = "something";
char * copy = new char[strlen(str)];
strcpy(copy, str);
// don't forget to delete[] copy when you're done
Oh, strdup() does just that, but it uses malloc, so you must free() the copy.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|