I am trying to convert an incoming byte array to a char array so that I
can display it to a field. This compiles but displays weird characters,
I really think this is wrong way to do it but I'm stuck.
I'd really appreciate some help if I could. Even if someone pointed me
to some examples.
Thanks a bunch!
Jevin
static void AppHexConvert() {
char i;
char bufP[5] = {0xFF,0x32,0x11,0x00,0x20};
char receivedBytes = 10;
WChar asciiChar[receivedBytes];
char tempCharacter;
FieldType *fldP;
FormType* frmP;
frmP = FrmGetActiveForm();
fldP = (FieldType *) FrmGetObjectPtr(frmP,
FrmGetObjectIndex(frmP, MainField));
for (i=0; i < receivedBytes; i++) {
tempCharacter = bufP[i] >> 4;
if ((tempCharacter <= 9) && (tempCharacter >= 0)) {
// Between 0 and 9
tempCharacter += '0';
} else if ((tempCharacter > 0) && (tempCharacter <= 15)) {
// Between 10 and 15
tempCharacter = tempCharacter - 10 + 'A';
} // Otherwise leave it raw
asciiChar[i*2] = tempCharacter;
tempCharacter = bufP[i+1] & 0x0F;
if ((tempCharacter <= 9) && (tempCharacter >= 0)) {
// Between 0 and 9
tempCharacter += '0';
} else if ((tempCharacter > 0) && (tempCharacter <= 15)) {
// Between 10 and 15
tempCharacter = tempCharacter - 10 + 'A';
} // Otherwise leave it raw
asciiChar[i*2+1] = tempCharacter;
}
FldInsert(fldP, asciiChar, receivedBytes);
}
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/