0

I'm trying to convert unsigned char to ascii text. How can I do it? I have tried this, but it is wrong:

typedef struct mtmheader
{
  unsigned char objName[20]; 
  unsigned char msgType[2];  
}mtmheader;

mtmheader h;
processMTMHeader(datap,&h, endmmsgp );
printf("Name, type: %s %c\n",(char *) &h.objName,(char *) &h.msgType);

EDIT I read stream of unsigned bytes and want to know what how can i print is as ascii text. In printf is only pseudo code, which is wrong.

MaMu
  • 1,837
  • 4
  • 20
  • 36

1 Answers1

4
printf("Name, type: %s %c\n", h.objName, h.msgType[0]);

should print the whole string objName and the first character from msgType.

For the first to work you'd have to be sure that objName is really null terminated.

Also unsigned char is not the correct type to use for strings use plain char without unsigned.

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177
  • I know , that `unsigned char` is not correct. this is my problem. that why i've sent this question. – MaMu Feb 10 '14 at 11:14