ListNode(const char* elements) : mPrev(0), mNext(0)
{
//Get the length of the string input into the constructor.
int length = strlen(elements);
//Assign enough memory to mNode to copy across the string.
mNode = new char[length];
//Copy across the new string.
strcpy(mNode, elements);
}
2 Replies - 745 Views - Last Post: 05 January 2011 - 11:29 AM
#1 Guest_Aequitas1*
Copying the contents of a Char array to another char array.
Posted 05 January 2011 - 10:57 AM
Hey there everyone, I'm attempting to copy the contents of a char array to another char array. The issue is the array I'm attempting to copy the string literal to is just a bad pointer. I have no idea how to proceed! Here is a sample of my constructor that I'm using to do this:
Replies To: Copying the contents of a Char array to another char array.
#2
Re: Copying the contents of a Char array to another char array.
Posted 05 January 2011 - 11:01 AM
You need to leave space for the null terminator: length + 1.
#3
Re: Copying the contents of a Char array to another char array.
Posted 05 January 2011 - 11:29 AM
> I have no idea how to proceed!
This is C++, so use a std::string and get on with life.
This is C++, so use a std::string and get on with life.
Page 1 of 1
|
|

New Topic/Question
Reply
MultiQuote







|