[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  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] Refresh page


Posted by Robert Powell   Australia  (367 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] 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
[Go to top] top

Posted by Robert Powell   Australia  (367 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] 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
[Go to top] 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.


11,586 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]