Help rewrite from C++ (avoid using ostringstream)
Hello,
I was given a task to modify our C application a little. I need to add a feature to log messages, with the file name being the same as a messageId (which comes as 24-byte array).
In another C++ application, the routine looks like this:
Code:
bool saveMessage(const string& path, const MQMD& md, const MQLONG len)
{
bool res = false;
ostringstream msgId;
unsigned char *pch;
string messageFileName;
ofstream fout;
int i;
msgId.fill('0');
msgId << hex;
pch = (unsigned char *)md.MsgId;
for (i = 0; i < sizeof(md.MsgId); i++)
msgId << setw(2) << (int)pch[i];
messageFileName = path + "/" + msgId.str() + ".msg";
// and now I can use messageFileName to whatever I want
}
I need to achieve the same functionality in plain C, but am strugling. I tried looping through the md.msgId a copying it byte by byte to unsigned char array, but to no avail.
Any help appreciated, thanx!