Array question

Hey

I was wondering if it's possible make an array containing strings? or is their any other way of accessing multiple strings easily?

Median

You can, but if you are planning on having a lot of strings, storing them in PROGMEM might be a better option...

Not more than 14 strings

I don't know how PROGMEM works, but can it write to the flash memory or is it read only?

My list is created when a certain button is pressed.

The strings in PROGMEM will stay the same during the entire program execution.

So is their any other way of storing strings in an array after the Arduino has been turn on?

You can create an array of strings. It's simply an array of pointers to arrays of characters.

char *strings[14]; // Allocate an array of pointers. Note that these don't point anywhere yet.

Then, make each pointer point somewhere:

char message1[50] = "Some string data";
strings[0] = message1;
strings[1] = strdup(message1); // Make a copy of the string
strings[2] = strings[1]; // Now there are two pointers to the same string

A little more detail about what you want to do, and the strings that are generated when a button is pushed would be helpful.

How do the strings dynamically relate to the button press, as opposed to being static strings that are displayed when the button is pressed?

I'm trying to make a menu system for an LCD display. The algorithm has to generate an array of strings which each corresponds to a menu element. (Does this make any sense?)

The button was just as an example of a trigger.

The strings, which will be in the list, are predefined and would probably be stored in the flash memory.

The algorithm has to generate an array of strings which each corresponds to a menu element.

The strings, which will be in the list, are predefined

Does this make any sense?

No. Either the strings are pre-defined or they are generated by the program.

~~The array is variable in length but the strings are predefined ~~
I’ve just found out, that in the bottom of this [http://www.arduino.cc/en/Reference/String] Arduino website, it explains how to make an array of strings. I have no idea how I missed this :-?

I’ve wrote this code to see if it has the desired effect, which it does

char* strings[]={"String1","String2","String3","String4","String5","String6"};
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
  lcd.begin(16, 2);
}

void loop() {
  for (int i = 0; i < 6; i++){
    if (i ==0) {
      lcd.setCursor(0,0);
      lcd.print("                ");
      lcd.setCursor(0,1);
      lcd.print(strings[i]);
    } else {
      lcd.setCursor(0,0);
      lcd.print(strings[i-1]);
      lcd.setCursor(0,1);
      lcd.print(strings[i]);
    }
    delay(500);
  }

I’m sorry wasting all of your time.

On a final note could you tell me the difference between:

char* strings[]

and
char *strings[X]? What difference makes it where the star-thingy is?

On a final note could you tell me the difference between: char* strings[]

and

char *strings[X]

? What difference makes it where the star-thingy is?

The placement of the * next to the variable name or next to the variable type is a matter of personal preference. It makes no difference to the compiler.