Is there any other function to add strings into buffer and updating values as well.
This is the problem I am coping with while using strcat()
char temp[2] = "A";
char temp_end[2] = "a";
char buf_adc[20]="alok";
char buf_hum[20]="lok";
char buf_temp[20]="vjf";
char buf[100];
void setup() {
Serial.begin(115200);
}
void loop() {
strcat(buf,buf_adc);
strcat(buf,temp);
strcat(buf,buf_hum);
strcat(buf,temp);
strcat(buf,buf_temp);
strcat(buf,temp_end);
Serial.println(buf);
}
1 Answer 1
strcat
always concatenates to the end of the string. Instead, for your first strcat
you should really be using strcpy
, which copies one string over the top of the other - that is, it places it at the start of the string, effectively starting a new string.
However, unless you really need the data in a string for some specific reason, you don't need to build a string up - just print each part to serial separately with its own Serial.print
function.