I was defining string1 at the beginning before the setup () like this:
int counter= 0; char string1[18] = ""; extern char* itoa(int a, char* buffer, unsigned char radix);
then in the loop () I did that:
counter++; itoa(counter, string1, 10); Spark.publish("Spark1", "The person number" + string1 + "produced a data", PRIVATE);
So I converted the integer storage, counter, to a character string, string1, to publish it on the cloud.
Is this a correct way to do it?
even after I defined the string1 as you suggested, I got the following error: no matching function for call to 'itoa(int&, String [1], int) invalid operands of types 'const char [18]' and 'String [1]' to binary 'operator+
If you want to stay with char array (C strings) and not use Arduino String objects, then I would switch to sprintf() like this:
int counter = 0;
char string1[65];
...
sprintf(string1, "The person number %d produced a data", counter++);
Particle.publish("Spark1",string1,PRIVATE);
Your suggestion worked for me, but I required to change the initial value for the counter to be equals 1 instead of 0 because I got this as the first person: