-1

KEIL 9.55

This works:

unsigned char code ID_Data_02[9]="\x02 1234567";

but what I really want is:

unsigned char code ID_Data_02[8]="\x021234567";

in the first case I just transmit using *(p+0), followed by *(p+2) and ignore the white space that is delineating the hex vs ASCII component.

Anyone know something tidier?

K&R defines \x to indicate 1 or more hex chars - tried \2x02 - seems like it's assumed the hex continues indefinitely until and non-0toF is encountered.

alk
  • 69,737
  • 10
  • 105
  • 255
JDL
  • 1

2 Answers2

5

Make use of string concatenation

unsigned char code ID_Data_02[8] = "\x02" "1234567";

Note that ID_Data_02 is not a string: it does not have space for the terminating zero byte. Using it with most str* functions invokes UB.

pmg
  • 106,608
  • 13
  • 126
  • 198
3

ANSI C concatenates adjacent strings into a single string so

unsigned char code ID_Data_02[8]="\x02" "1234567";

does what you want

Tim Wright
  • 31
  • 3