Question about using array with sprintf() to send file to sd and to cloud

Hi,

I would like to ask for some help. I want extend my code. Now I am writing temperature values to array ( for example char pageadd[128] ) with sprintf.
Than sending it to the cloud and also to SD card:

sprintf(pageAdd,"/update?key=XXXXXXXXXXXXX&field1=%i&field2=%i&field3=%i&field4=%i&field5=%i",temp0,temp1,temp2,temp3,temp4);
if(!getPage(server,pageAdd)) Serial.print(F("Fail "));
 else Serial.print(F("Pass "));

defining logfile and sending to SD:

int logFile(char* sdate, char* stime, int temp0, int temp1, int temp2, int temp3, int temp4) {
 
  File fh = SD.open("xyz.txt",FILE_WRITE);
  if(!fh) {
    Serial.println(F("Open fail"));
    return 0;
  }

  sprintf(pageAdd,"%s,%s,%i,%i,%i,%i,%i;",sdate,stime,temp0,temp1,temp2,temp3,temp4);
 
  fh.println(pageAdd);
  fh.close();
  return 1;

This cloud cannot handle more than 8 fields for one sending. So I would like to send with another update key another 5 values.

Do I have to use another array instead of PageAdd for example? The lenght is ok, but should it be empty before new sending? I am confused.
Or I have just another sprintf defined like:

sprintf(pageAdd,"/update?key=YYYYYYYYYYYYYY&field1=%i&field2=%i&field3=%i&field4=%i&field5=%i",temp5,temp6,temp7,temp8,temp9);

Thank you!

If you use sprintf() twice with the same buffer array then the second use will overwrite the first and add the null terminator at the appropriate place. For example

int bb1 = 12345;
int bb2 = 678;
char buffer[10];

void setup() 
{
  Serial.begin(115200);
  sprintf(buffer, ">%d<", bb1);
  Serial.println(buffer);

  sprintf(buffer, ">%d<", bb2);
  Serial.println(buffer);
}

void loop() 
{
}

That sound perfect in this case! Thanks for UKHeliBob helping again with sprintf !!!

As a general guide, I recommend using snprintf() rather than sprintf(), to protect you from overrunning the bounds of the array.