On Sat, 1 Dec 2001, Daniel A. Koepke wrote:
> How about:
>
> int create_entry(char *name)
> {
> .
> .
> .
> } else if ((pos = get_ptable_by_name(name)) == -1) { /* new name */
> i = ++top_of_ptable + 1;
>
> RECREATE(player_table, struct player_index_element, i);
> pos = top_of_p_table;
>
> /*
> * Since the name is the same and already allocated for deleted
> * players, we only CREATE and set for new names.
> */
> CREATE(player_table[pos].name, char, strlen(name) + 1);
>
> /* copy lowercase equivalent of name to table field */
> for (i = 0; (player_table[pos].name[i] = LOWER(name[i])); i++)
> /* Nothing */ ;
> }
>
> return (pos);
> }
I just tested this solution, and it doesn't work when the player table is
empty! So instead of moving the create/copy, I now have it almost as before,
but only create/copy the name if the field is NULL:
int create_entry(char *name)
{
.
.
.
if (...) {
.
.
.
} else if (...) {
.
.
.
}
/* new check added */
if (player_table[pos].name == NULL) {
/* create a new name (as before) */
.
.
.
}
return (pos);
}
/ Joachim
=======================================================================
The Arrow http://pileborg.org/~arrow/
Joachim Pileborg mailto:arrow@tpileborg.org
=======================================================================
"Everyone wants to go to heaven, but no one wants to die" - Two Witches
--
+---------------------------------------------------------------+
| FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
| Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
+---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 06/24/03 PDT