On Wed, 8 Oct 1997, --Ben Horner-- wrote:
> I am a new coder to c and have a memory allocation question,
>
> Ok I set up a number of arrays containing selected phrases such as:
> fantastic, good etc etc for my stats rolling system.
>
> In the call that calls my function for rolling I added a array for these
> to go into, thus:
> I call my function and it returns a array of ONE of the selected phrases.
>
> Now I understand that c allocates memory for a simple array of one
> number, but can it allocate memory for this type of array? where it has a
> selection of phrases to store?, do I need to malloc this and if so how?
>
> The examples of malloc I have seen all refer to a linked structure, this
> is definatly not a linked structure as in a section of code it is:
>
> char *rolls_abils_result[5] = {"&0&1&bFantastic&0 ", "&0&2&bPretty
> Good&0", "&0&3&bNot bad&0 ", "&0&3Fiar&0 ", "&0&9&bBad&0 ;
I'm not sure, but I think that you can't put the * for pointer... here is
what it should look like:
char roll_abils_result[5] = {
"Fantastic", /* 0 */
"Pretty Good", /* 1 */
"Not Bad", /* 2 */
"Fair", /* 3 */
"Bad" /* 4 */
};
to call one, you just use "roll_abils_result[x]", x being the position in
the array.. which are commented out along the side.. hope this helped..
/-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+-=-=-=-=-=X=-=-=-=-=-=-=-=-=-=-=-\
| Brian M. Williams | 02/02/83 | bmw@efn.org |
X=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+=-=-=-=-=-+-=-=-=-=-=-=-=-=-=-=-=X
| Boccob the Uncaring, Lord of All Magic | Nashak Stonehand |
| accolademud.hermesnet.net 5000 | coyote.toon.org 6000 |
\=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-X-=-=-=-=-=-=-=-=-=-=-=/
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/08/00 PST