converting two char arrays into byte buffer

hello,
I need to make byte array from two char arrays using following code:

  char latt[9];
  char lngt[9];   
    
  dtostrf(gps_lat, 2, 6, latt);
  dtostrf(gps_lng, 2, 6, lngt);

  String message = lngt + latt;

but I am getting this compiler error:

"invalid operands of types 'char [9]' and 'char [9]' to binary 'operator+'"

can you help please what I'm doing wrong or to convert those two GPS numbers into byte buffer?

Are you confusing strings (lowercase s) which are null terminated arrays of chars, with Strings (uppercase S) which are objects created using the String library ?

The two data types are manipulated using different functions and they are not generally interchangeable.

no,sorry, there is uppercase "S" in string in my code, I have edited it...

Can you please describe what the dtostrf() function does and what the type and meaning of the 4 parameters is ? Where do the values of the gps_lat and gps_lng variables come from and how are they declared ?

dtostrf() function converts gps_lat and gps_lng double variables into latt and lngt char arrays. Those two numbers are number of digits before and after decimal point.

for example "latt" can be 48.039289

In an attempt to show the memory cost of using the String class, I wrote this little test program:

void setup() {
  // put your setup code here, to run once:

  char latt[9];
  char lngt[9];   
  float gps_lat = 33.25;
  float gps_lng = 50.11;

  Serial.begin(9600);
/*  
  dtostrf(gps_lat, 2, 6, latt);
  Serial.println(latt);
  dtostrf(gps_lng, 2, 6, lngt);
  Serial.println(lngt);
*/
    
  dtostrf(gps_lat, 2, 6, latt);
  dtostrf(gps_lng, 2, 6, lngt);
  Serial.println(latt);
  Serial.println(lngt);
}

void loop() {

}

When I run this, all I get out is 50.110001. I don’t see the latitude. If I comment out the current block and uncomment the first block, I get the correct output. I’m running 1.6.9 on a Mega 2560 wiht a PC running Win 7 with a megamunch of memory. Does anyone else get strange results, or am I missing something obviouos?

Those two numbers are number of digits before and after decimal point.

No. The first number is the total field width including the .
48.039289 is a field width of 9.

dtostrf(gps_lat, 9, 6, latt);
dtostrf(gps_lng, 9, 6, lngt);

In order to provide sufficient memory in latt and lngt to handle the null termination they need declaration as

char latt[10];
char lngt[10];

ecnojacks code prints both numbers with those corrections.

void setup() {
  // put your setup code here, to run once:

  char latt[10];
  char lngt[10];   
  float gps_lat = 33.25;
  float gps_lng = 50.11;

  Serial.begin(9600);
/*  
  dtostrf(gps_lat, 2, 6, latt);
  Serial.println(latt);
  dtostrf(gps_lng, 2, 6, lngt);
  Serial.println(lngt);
*/
    
  dtostrf(gps_lat, 9, 6, latt);
  dtostrf(gps_lng, 9, 6, lngt);
  Serial.println(latt);
  Serial.println(lngt);
}

void loop() {

}

cattledog:
No. The first number is the total field width including the .
48.039289 is a field width of 9

The first value is the minimum width. It can be less than the required width for the full string including the decimal point. It can even be set to zero. It only has an effect if the string has less characters than the value set by (minimum) width, in which case the string is padded out with blank spaces to that minimum width.
This illustrates it well:-

void setup()
{
    //  dtostrf(val, width, precision, buffer);

    Serial.begin(115200);
    double dVal = 123.4567;
    char buffer[10];
    
    dtostrf(dVal, 0, 3, buffer);  // Prints "123.457"
    Serial.println(buffer);

    dtostrf(dVal, 6, 2, buffer);  // Prints "123.46"
    Serial.println(buffer);

    dtostrf(dVal, 7, 2, buffer);  // Prints " 123.46"
    Serial.println(buffer);
}

void loop(){}

yoopee:
no,sorry, there is uppercase "S" in string in my code, I have edited it...

As said in the first reply, you can not concatenate two character arrays to create a String (with capital S).

If you insist living dangerously with String, you can convert the character arrays to Strings and concatenate those.

  String message = String(latt) + String(lngt);

And one (of many) better solutions

// create a message buffer with enough space for the largest message; in this case 9 plus 9
// also needs space for terminating nul character
char message[19];
strcpy(message, latt);
strcat(message, lngt);