char* array get length of string?

With an array like this.....

char* myStrings[]={"This is string 1", "This is string 2", "This is string 3",
"This is string 4", "This is string 5","This is string 6"};

What is the correct way to get the length of "myStrings[x]" to give the number of characters?

Will it require adding string.h to the sketch?

I am sure it's simple, but I have searched for hours now and still no answer! :confused:

Thanks if you can help!

size_t l = strlen(myString[0]);

On the arduino, you can almost certainly use int instead of size_t.
string.h is automagically added.

char* myStrings[] = {"This is string 1", "This is string 2", "This is string 3",
                     "This is string 4", "This is string 5", "This is string 6"
                    };
void setup() {
  Serial.begin(115200);
  int totalLength = sizeof(myStrings);
  Serial.print(F("Size of the array is "));
  Serial.println(totalLength);
  for (byte idx = 0; idx < sizeof(myStrings) / sizeof(myStrings[0]); idx++) {
    int thisLength = strlen(myStrings[idx]) + 1;
    Serial.print(F("Size of element "));
    Serial.print(idx);
    Serial.print(F(" is "));
    Serial.println(thisLength);
    totalLength += thisLength;
  }
  Serial.print(F("Total size of the array and the strings is "));
  Serial.println(totalLength);
}

void loop() {}
Size of the array is 12
Size of element 0 is 17
Size of element 1 is 17
Size of element 2 is 17
Size of element 3 is 17
Size of element 4 is 17
Size of element 5 is 17
Total size of the array and the strings is 114

He wanted the number of characters, so I assume that that does not include the '\0', though I guess that is technically a character. 8^)

For me a '\0' is a character.

I knew it would be easy :wink:

Thank you both for the help!

:slight_smile: :slight_smile: :slight_smile:

Now I only have one other thing to sort out and the project is done!