[Solved] How can I add to a String array

I'm needing to be able to declare an array of type String, without knowing before hand how many strings (in this case, file names from an SD Card) there will be to place in it.

I had hoped the below would work:

  String strAr[];

  strAr[0] = "This is a test";
  strAr[1] = "this is another test";
  strAr[2] = "This is a third";

  Serial.println(strAr[0]);
  Serial.println(strAr[1]);
  Serial.println(strAr[2]);

But the first line give the error message:

"storage size of 'strAr' isn't known"

What syntax can I use to add more cells to a String array?

It doesn't work like that in c. You need to define size.

You could make a linked list and malloc each item. Try Googling "C linked list".

In your examples you are only declaring/initialising the array, not adding to it.

I find the Arduino Reference page invaluable.

Under Data Types you will find how to use arrays.

The second linked page will give you all the possible ways to declare/initialise an array.

If you declare the array without initialising it, you can use strcpy() to initialise it.
Once you have the array initialised, you can use strcat() to add to it.

It is an array of String objects, not an array of characters.

Oops - sorry. Please ignore/delete my previous post and this one.

Don't worry about it. Why anyone would want an empty array of String objects mystifies me.

Yeah, I hear you on that, Nick.

When I was using three Uno's (with Atmega328 chips) -- linked together with "SoftwareSerial" -- memory was far to precious to waste on real Strings. Everything was done instead with char arrays to conserve space. But now that I've converted the project to a single (but much bigger) Atmega1284 chip, memory use by real Strings is no longer an issue.