On Fri, 14 Jun 2002, Jeremy Hill wrote:
> *slaps forehead* Knew it had to be easy. Duh.
>
> Any other ways of doing it? Specifically, a more sophisticated way of having
> multiple divisions without needing to do the whole if check/strcpy/whatnot? I
> always have in mind something like this:
> clan_table[ch->clan].division[ch->clandivision].name.
Sure. Just change:
struct clan_type
{
...
char *division_one_name;
char *division_two_name;
...
};
into:
#define NUMBER_OF_DIVISIONS 2
struct clan_type
{
...
char *division[NUMBER_OF_DIVISIONS];
...
};
The clan table would be initialized exactly the same way as before,
when you had multiple char * variables in the structure. The only
difference is the naming of those variables.
You could then refer to it as:
clan_table[ch->clan].division[ch->clandivision]
And since arrays are 0-based, you'd want to start your division numbers
at 0, and pick another number such as -1 to indicate no division.
Now onto your previous post:
> >Here's where I'm running into problems:
> >
> >char *divbuf[MAX_STRING_LENGTH];
divbuf is an array of 4608 pointers to char.
> > if (ch->clandivision > 0 && ch->clandivision < 3)
> > {
This whole structure of these if statements is a bit weird.
(Logically correct, but not too straightforward).
if (ch->clandivision == 1)
divbuf = clan_table[ch->clan].division_one_name;
else if (ch->clandivision == 2)
divbuf = clan_table[ch->clan].division_two_name;
would do the same thing, and get rid of the unnecessary nested if.
(This still isn't correct unless the 'divbuf =' lines are fixed)
But using an array like you wanted would still be better.
> > if (ch->clandivision == 1)
> > divbuf = clan_table[ch->clan].division_one_name; (line 1202)