0

like the topic mention.... for example

int[10] msg;

msg[0] = 1;
msg[1] = 2;

const char* a = (const char*)msg[0];      
const char* b = (const char*)msg[1];

It seem there is no value when I test by printf

I'm going to use it this way

char test[20];
strcpy(test, a);
strcat(test, ",");
strcat(test, b);
strcat(test, "\0");
mclient.publish("topic1/sensorAck",test);

The result show only comma

Jongz Puangput
  • 5,527
  • 10
  • 58
  • 96

2 Answers2

1

strcpy and strcat both stop when they reach a '\0' character in the source string. Since int 1 is actually 4 bytes (0, 0, 0, 1), it will stop on the first byte, because it's zero '\0' and never reach the '1' value byte.

ben
  • 341
  • 1
  • 4
0

Here's the C code to convert an integer into a C string.

int i = 1;
char text[12];
sprintf(text, "%d", i);
Neil Kirk
  • 21,327
  • 9
  • 53
  • 91