Concatenate 3 integers to a space deliminated string in Arduino

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);


}

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).

链接地址: http://www.djcxy.com/p/73210.html

上一篇: 为什么在C ++ 11中'i = i ++ + 1`未定义的行为?

下一篇: 将3个整数连接到Arduino中的空格字符串