havman56
asked on
char * address to char array
I want to copy a address of char* buffer to char array.
(pStMessage_t->m_bufferDat a) = (pMessage->GetData());
here pMessage->GetData() returns char*.
pStMessage_t->m_bufferData is array.
how do i get address of (pMessage->GetData()) point to address array.
(pStMessage_t->m_bufferDat
here pMessage->GetData() returns char*.
pStMessage_t->m_bufferData
how do i get address of (pMessage->GetData()) point to address array.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi havman56
If the pStMessage_t->m_bufferData declared as char[] then you CAN'T simply do something like "pStMessage_t->m_bufferDat a = pMessage->GetData()". Actually "char[]" is the same as "char * const" (note the "const" keyword, it means that you pointer is const). This means for you that you can change the data inside the array but you can not reference to another buffer by this variable. Every C/C++ book says that in this situation you should copy content of the buffer (e.g. using strcpy()) instead of copying pointers. Also please look at the help for pMessage->GetData() and find out who should free the memory, returned pointer refers to.
Let me know if you have further questions about it.
Pavlik
If the pStMessage_t->m_bufferData
Let me know if you have further questions about it.
Pavlik
ASKER
i am very much thanksful for all the answers i agree with all ones.
but i feel nietod given some theory based on his answers so i am accepting as answer.
jhance and pavlik also given right one.
thanks for immed response from all
but i feel nietod given some theory based on his answers so i am accepting as answer.
jhance and pavlik also given right one.
thanks for immed response from all
char lpszString[32];
const char *lpszConstString = "This is a test";
strcpy(lpszString, lpszConstString);
is legal. So in your case, you should be able to do:
char *buffer = pMessage->GetData();
buffer = pStMessage_t->m_bufferData
Now buffer points to the string...