I have an array (array) that contains some char that are numbers:
char array[] = [20, 3, 32, 34, -12] //for example
I want to include this numbers for calling a function in the following way:
for array[0], the message to send would be "R 20". For array[1], it would be "R 3"...
sendtoserver("R 20");
How can I do this? I know I need a "for" loop for all of them, but my question is how do I get the "R array[0]" to be "R 20".
Thanks in advance!
sprintf it to a sufficiently sized buffer and pass the buffer:
char buf[14];
//14 is enough for "R " (2) +
//the decimal representation of any 32 bit int (11) + '\0' (1)
//2 + 4 + 1 = 7 would be enough for sized, 8 bit chars
sprintf(buf, "R %d", array[i]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With