const char *echo_strings[4]

Posted by Robert Powell on Mon 14 Jul 2014 09:25 AM — 4 posts, 16,976 views.

Australia #0

const char *echo_strings[4] = {
                     "The day has begun.\r\n",
                     "The day has begun.\r\n",
                     "The sky slowly begins to glow.\r\n",
                     "The sun slowly embarks upon a new day.\r\n"
                  };


Are the elements in this numbered 1-4 or 0-3 as I am making modifications to similar things and wish to use number_range rather than number_bits for selecting the random strings.
Australia Forum Administrator #1
C arrays always start at zero.
Australia #2
Nick Gammon said:

C arrays always start at zero.


Why does the compiler complain if I change 4 to 3 then. 4 elements would be 0,1,2,3, but putting 3 instead of 4 gives error: too many initializers for ‘const char* [3]’
};

Kind of confused with what is happening, because i have some arrays that have 5 elements but with them, const char* [4] the compiler likes.
Amended on Mon 14 Jul 2014 10:36 PM by Robert Powell
Australia Forum Administrator #3
You have 4 elements, I can see them.

As you say, they are 0, 1, 2, 3.

Total of 4, and thus you can have up to 4 initializers.

Quote:

Kind of confused with what is happening, because i have some arrays that have 5 elements but with them, const char* [4] the compiler likes.


Example code?