Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ const char *echo_strings[4]
const char *echo_strings[4]
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Robert Powell
Australia (367 posts) Bio
|
Date
| Mon 14 Jul 2014 09:25 AM (UTC) |
Message
|
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. |
Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Mon 14 Jul 2014 10:04 PM (UTC) |
Message
| C arrays always start at zero. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Robert Powell
Australia (367 posts) Bio
|
Date
| Reply #2 on Mon 14 Jul 2014 10:35 PM (UTC) Amended on Mon 14 Jul 2014 10:36 PM (UTC) by Robert Powell
|
Message
|
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. |
Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #3 on Tue 15 Jul 2014 (UTC) |
Message
| 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? |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
13,256 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top