I think my understanding of byte arrays and char arrays is causing some problems, here is my problem:
I have an application that retrieves messages from Websphere MQ and sends them to the target system.
The MQ message has MQBYTE24 (byte 24 essentially), which represents the MSGID of the message. My goal is to convert this to a hexadecimal string.
In the WMQ explorer on my Linux box, message 1 in the queue has the message identifier "AMQ QM01" (at least that's what it looks like), and the bytes below, as shown in the explorer:
00000 41 4D 51 20 51 4D 30 31--20 20 20 20 20 20 20 20 |AMQ QM01 | 00010 BD F4 A8 4E A2 A3 06 20-- |...N... |
Now that my code is running, I pick up the same message id and try to convert it to a hexadecimal string.
ID of the exact message during debugging:
AMQ QM01 \ 275 \ 364 \ 250N \ 242 \ 243 \ 006
And after completing my conversion (code below) I get:
414D5120514D30312020202020202020FFFFFFFF4EFFFF6
As you can see, this is a little different from what WMQ Explorer shows, any idea what I'm doing wrong here?
I assume that I am switching from MQBYTE24 to char .... there is something wrong ...
Below is a small sample program that creates the βwrong resultβ ..... I am assune, should I use a byte array instead of char?
The output for the following:
Result: 414D5120514D30312020202020202020FFFFFFFF4EFFFF6
#include <stdio.h> #include <string.h> #include <stdlib.h> int main(){ char name[41]="AMQ QM01 \275\364\250N\242\243\006"; char buffer[82]=""; char *pbuffer = buffer; FILE *fp_1; FILE *fp_2; int size; char *buffer_1 = NULL; char *buffer_2 = NULL; int rc = convertStrToHex(buffer, name); printf( "Result: %s\n", pbuffer ); } return 0; } int convertStrToHex(char *buffer, char str[10]){ int len = strlen(str); int i; for( i = 0; i < len ;i++ ){ sprintf(buffer, "%X", str[i]); buffer +=2; }; }
Thanks for the help: -)
Linton