
March 20th, 2003, 03:06 AM
|
|
Contributing User
|
|
Join Date: Feb 2001
Posts: 1,365

Time spent in forums: 18 h 9 m 25 sec
Reputation Power: 14
|
|
|
You can create a pointer with new and for the char array size use the length of the char pointer you want to copy + 1. Then, you can use strcpy() to copy one char pointer to the other:
pnew_string = new char[strlen(pstring) + 1];
strcpy(pnew_string, pstring);
pstring must contain a c-style string, i.e. one that's terminated with \0. (include <cstring>)
If your pointer doesn't contain a c-style string, you can use a for-loop to copy one character at a time using pointer notation:
pnew_string= new char[pstring_length];
for(int i=0;i<pstring_length; i++)
{
*(pnew_string + i) = *(pstring + i);
}
Last edited by 7stud : March 20th, 2003 at 05:22 AM.
|