Just create a buffer of a maximum value and copy in the value you want while remembering the length of the array.
#define MAX_ARR_LENGTH (4)
void time_Text(int PastTo_val) {
int tPTT_x[MAX_ARR_LENGTH];
int tPTT_y[MAX_ARR_LENGTH];
const int tptt_y_case_1[] = {11, 11, 11, 11};
const int tptt_x_case_1[] = {6, 7, 8, 9};
const int tptt_y_case_2[] = {11, 11};
const int tptt_x_case_2[] = {10, 11};
int filled = 0;
switch (PastTo_val) {
case 1:
{
memcpy(tPTT_x, tptt_x_case_1, sizeof(tptt_x_case_1));
memcpy(tPTT_y, tptt_y_case_1, sizeof(tptt_y_case_1));
filled = 4;
}
break;
case 2:
{
memcpy(tPTT_x, tptt_x_case_2, sizeof(tptt_x_case_2));
memcpy(tPTT_y, tptt_y_case_2, sizeof(tptt_y_case_2));
filled = 2;
}
break;
}
Serial.println("Printing array values");
for(int i=0; i < filled; i++) {
Serial.println("tPPT_x["+ String(i) +"] = " + String(tPTT_x[i]));
Serial.println("tPPT_y["+ String(i) +"] = " + String(tPTT_y[i]));
}
}
Depending on whether you need to modify the memory you can also just point to constant memory and remember the length.
void time_Text(int PastTo_val) {
const int* tPTT_x; //Pointers to the values
const int* tPTT_y;
//You make also add "static" if you want to reference this
//data beyond the scope of the function
const int tptt_y_case_1[] = {11, 11, 11, 11};
const int tptt_x_case_1[] = {6, 7, 8, 9};
const int tptt_y_case_2[] = {11, 11};
const int tptt_x_case_2[] = {10, 11};
int filled = 0; //number of elements
switch (PastTo_val) {
case 1:
{
tPTT_x = (const int*) tptt_x_case_1;
tPTT_y = (const int*) tptt_y_case_1;
filled = 4;
}
break;
case 2:
{
tPTT_x = (const int*) tptt_x_case_2;
tPTT_y = (const int*) tptt_y_case_2;
filled = 2;
}
break;
}
Serial.println("Printing array values");
for(int i=0; i < filled; i++) {
Serial.println("tPPT_x["+ String(i) +"] = " + String(tPTT_x[i]));
Serial.println("tPPT_y["+ String(i) +"] = " + String(tPTT_y[i]));
}
}