define array of strings

I am trying to create a library which will contain a function to send a html page. This function will load a pagea from SPIFFS and replace variables with values, like "Hi %name%, how are you" should translate to "Hi Name, how are you". I do this with the following function (it is not yet generic for page name. This will follow):

void serverSendPage (WiFiClient client, String paramName[], String paramValue, int n) {
  if (client) {
    client.println("HTTP/1.1 200 OK");
    client.println("Content-Type: text/html");
    client.println("Connection: close");
    client.println();
    client.println("<!DOCTYPE HTML>");
    if (SPIFFS.exists("/page/index.php")) {
      File f = SPIFFS.open("/page/index.php","r");
      while(f.available()) {
        String line = f.readStringUntil('\n');
        for (byte i=0;i<n;i++) {
          line.replace("%"+paramName+"%",paramValue[i]);
        }
        client.println(line);
      }
    }
    delay(1);
    client.stop();
  }
}

This works if I send 2 String arrays. What I want to do however is #define the names and only have the values as actual String array, like this:

#define NAMES { "name", "color", "food" }

....

  String values[3];
  values[0] = "Name";
  values[1] = "Blue";
  values[2] = "Bread";
  serverSendPage(client,NAMES,values,3);

This however does not work. I get an error:
cannot convert '' to 'String*' for argument '2' to 'void serverSendPage(WiFiClient, String*, String*, int)'

Since the NAMES will not change during the exection of the program, I wanted to have them defined as some sort of array.

What can I do to accomplish this?

BTW, I have tried by just sending the values with a count and replace %0% with a valuue etc. This works but if possible I want to use meaningful names in my code instead of numbers.

Any suggestions?

Something like below ??

const char *names[] = {"aa", "bb", "cc"};

Well your post seens utterly confusing...

Let's go from the beggining.

Firstly you are using Strings (capital letter), you really should avoid that and use char arrays instead. It's a bit harder concept but, it's totally worth it and you will probably end up moving to char arrays sooner or later.

Secondly, this don't make any sense at all.

jeroenb42:
This works if I send 2 String arrays. What I want to do however is #define the names and only have the values as actual String array, like this:

#define NAMES { "name", "color", "food" }

This however does not work. I get an error:
cannot convert '' to 'String*' for argument '2' to 'void serverSendPage(WiFiClient, String*, String*, int)'

You can define it, or you can use a String, or a char array as I already recomended, but you can't do both at the same time.

This would work, for example.

#define NAMES "name"
String NAMES = "name";
char NAMES[]  = "name";
char NAMES[][6] = {"name", "color", "food"};

Now, this is completely another thing. You should understand what you are doing before starting to worry about this.

jeroenb42:
Since the NAMES will not change during the exection of the program, I wanted to have them defined as some sort of array.

When you are using something that don't change at compiling time you should use PROGMEM to save it on the Arduino flash memory. It does have some caveats when acessing that memory, but once you get used to it, it's not a big problem, and your RAM will thank you latter.

For example:

const char NAMES[][6] PROGMEM = {"name", "color", "food"};

This:

#define NAMES "name"
String NAMES = "name";
char[] NAMES = "name";
char [3][] NAMES = {"name", "color", "food"};

would be resolved by the pre-processor to:

String "name" = "name";
char[] "name" = "name";
char [3][] "name" = {"name", "color", "food"};

which is complete nonsense...

Regards,
Ray L.

RayLivingston:
which is complete nonsense...

Regards,
Ray L.

Ops... Indeed.
I was typing directly in the reply and got carried away, I will correct the post.
Thanks.