0

I have two non constant char arrays. One is "buff" and other is "buffa". I get values in buffa via rf transmitter of other Arduino and I want to append those data to the data inside of buff. Then I will send all data to other Arduino. So I don't want to send two different char arrays. I want to send them all at once as just one array.

I TRIED SPRINTF BUT IT DOESNT WORK.

char buffa[144]; 
    char buff[1000];


void loop() {

  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  sprintf(buff,"<status>\n");    



    if (vw_get_message(buf, &buflen)) { // check to see if anything has been received
      int i;
      for (i = 0; i < buflen; i++) {
        buffa[i] = (char) buf[i];  // the received data is stored in buffer

      }
    }


  distance1 = getDistance(initPin1, echoPin1);
  sendData(3, distance1);

  sprintf(buff, "%s", buffa);




delay(5000);
 const char *msg0 = buff;


 vw_send((uint8_t *)msg0, strlen(msg0)); // Send control character 
 vw_wait_tx();

 Serial.print(msg0);

}

1 Answer 1

3

Assuming the data in buffa is a c-style string (i.e. null-terminated), replace

sprintf(buff, "%s", buffa);

with

strcat( buff, buffa );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.