I want to assign string to char array
here is code –
char *resultArray[100];
int cnt = 0;
void MySAX2Handler::startElement(const XMLCh* const uri, const XMLCh* const localname,
const XMLCh* const qname, const Attributes& attrs)
{
char* message = XMLString::transcode(localname);
resultArray[cnt] = message;
cnt++;
for (int idx = 0; idx < attrs.getLength(); idx++)
{
char* attrName = XMLString::transcode(attrs.getLocalName(idx));
char* attrValue = XMLString::transcode(attrs.getValue(idx));
resultArray[cnt] = attrName;
cnt++;
resultArray[cnt] = attrValue;
cnt++;
}
XMLString::release(&message);
}
after iterating through resultArray, its printing some garbage values
attrNameandattrValueare both pointers andcharis a type of integer, so the assignment operator will simply copy the value of the pointer (the address), not the content.Either loop through the strings or use some version of
strcpy(), or indeed one of the C++ string libraries.