a small strcpy / strcat problem

hey i have a piece of code where I want to collect data.
I have minimized it so you can more easily help me to solve the problem.
code looks like this:

#include <SPI.h>

char test[0xFF]={
  "input"};
char data[0xFF];


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


}

void loop()
{
  delay(1000);
  strcpy(data,"data=1,2,3,4,5");

  strcat(test,data);
  Serial.println(test);

  delay(1000);

}

The problem is that data = 1,2,3,4,5 duplicate the in each loop.
it should only be there once.


output:
inputdata=1,2,3,4,5
inputdata=1,2,3,4,5data=1,2,3,4,5
inputdata=1,2,3,4,5data=1,2,3,4,5data=1,2,3,4,5
inputdata=1,2,3,4,5data=1,2,3,4,5data=1,2,3,4,5data=1,2,3,4,5
inputdata=1,2,3,4,5data=1,2,3,4,5data=1,2,3,4,5data=1,2,3,4,5data=1,2,3,4,5
inputdata=1,2,3,4,5data=1,2,3,4,5data=1,2,3,4,5data=1,2,3,4,5data=1,2,3,4,5data=1,2,3,4,5

Expected output:
inputdata=1,2,3,4,5
inputdata=1,2,3,4,5
inputdata=1,2,3,4,5
inputdata=1,2,3,4,5

what am I doing wrong.

You never clear "test" back to an empty string.

Hey I have figured out, but I can not figure out how to delete it.

  strcpy (test, "");
  strcat (test,data);

Hey thanks a lot for The help.

Why call strcpy? Just set the first character to 0:

  *test = 0;
  strcat (test,data);

or

  test[0] = 0;
  strcat (test,data);

hi I will try later.
Right now I've moved on but has a new irritating problem.
code looks like this:

strcpy(data,"&data=");
  dst = data + strlen(data);
  dst += sprintf(dst, "%ul", 1);
  
  strcpy(test,"/invput?id=1234");

  strcat(test,data);
  Serial.println(test);
  strcpy (test, "");

I expect to get:
/invput?id=1234&data=1

but I get:
/invput?id=1234&data=1l

where does the l come from.

From %ul ? Format unsigned longs with %lu not %ul

http://www.cplusplus.com/reference/cstdio/printf/

That's a good question... Are you sure you're seeing =1| and not =1l ? The "unsigned long" isn't "%ul" as you would expect, but "%lu". The format is:

%<flag><width><precision><length><conversion>

You have a length of "l" for "long", and a conversion of "u" for "unsigned". With "%ul" you have a conversion of "u" for unsigned, and then an "l" on the end.

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA yes Yes of course .. my mistake .. Thanks for The help.