Concatenate 3 integers to a space deliminated string in Arduino

user3242950 Source

I'm currently trying to concatenate 3 integers to a space deliminated string. However, I can't seem to get the correct syntax. Am I missing a certain function that will help me put the string together? Below is the code I'm trying to use that should perform the function.

I'm currently getting the error:

test.ino: In function 'void conv_display_f(unsigned char*, float*)': test:50: error: invalid conversion from 'unsigned char*' to 'char*' test:50: error: initializing argument 1 of 'int snprintf(char*, size_t, const char*, ...)'

float flon = 11.11;
unsigned char lon_digits[10];


void setup()
{
  Serial.begin(9600);  
  Serial.println();

}

void loop()
{
  conv_display_f(lon_digits, &flon);


void conv_display_f(unsigned char *loca, float *cord)
{
  int deg, minute, seconds;
  char degC[3], minC[2], secC[3];


  float temp = cord[0];
  deg = floor(temp);
  minute = floor((temp-deg)*60);
  seconds = (((temp-deg)*60)-minute)*60;

  snprintf(lon_digits, sizeof(lon_digits), "%d %d %d", deg, minute, seconds);


}
carduino

Answers

answered 4 years ago Mahonri Moriancumer #1

Perhaps you could use 'snprintf()'?

char string[100+1];
...
snprintf(string, sizeof(string), "%d %d %d", deg, minute, seconds);
...

Or, perhaps:

snprintf(string, sizeof(string), "%d %d %d", atoi(deg), atoi(minute), atoi(seconds));

or:

snprintf(string, sizeof(string), "%s %s %s", deg, minute, seconds);

(I am somewhat confused as to where you are intending to do the concatenation in your code).

comments powered by Disqus