output char array with snprintf

How can I easily output all elements of an array in a snprintf function?

// this is the way for Serial output 
int temperatureNumDevices = 5; 
 
for (int i=0; i<temperatureNumDevices; i++) {
 Serial.print(temperatureArrayChar[i]);
}

and I can this do with snprintf by defining every single array element in sprintf

snprintf(buffer, size, "%s,%s,%s,%s,%s", temperatureArrayChar[0], temperatureArrayChar[1], temperatureArrayChar[2], temperatureArrayChar[3], temperatureArrayChar[4]);

But I want do something like

snprintf(buffer, size, "%s,[x temperatureNumDevices]", temperatureArrayChar[0 to temperatureNumDevices]);

to have the code flexible in case temperatureNumDevices is changing. Can I do this in snprintf directly or do I have to make some helper variables with the values of the array?

You will not be able to have it the way you want it, because "0 to temperatureNumDevices" is no valid C-expression,
but you could write a routine, that supplies the functionality you are looking for, something like

int xsnprintf(char* buff, int len, char* verySpecialFormat, void* arrayData, int elements);

you could try to build a buffer, concatenating each value using a for loop interspersed with commas and then null-terminate it.

then print it like any C string...