From 62faa7c848be51198dcbdb6645edfe6cbfeb4a42 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sun, 31 Dec 2023 20:38:22 +0100 Subject: Reformatted get_empty_slot() --- FICS/playerdb.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/FICS/playerdb.c b/FICS/playerdb.c index feb5f8f..051dd98 100644 --- a/FICS/playerdb.c +++ b/FICS/playerdb.c @@ -45,26 +45,24 @@ PUBLIC player parray[PARRAY_SIZE]; PUBLIC int p_num = 0; -PRIVATE int get_empty_slot(void) +PRIVATE int +get_empty_slot(void) { - int i; + for (int i = 0; i < p_num; i++) { + if (parray[i].status == PLAYER_EMPTY) + return i; + } - for (i = 0; i < p_num; i++) { - if (parray[i].status == PLAYER_EMPTY) { -/*** fprintf(stderr,"New player put in parray[%d/%d]\n", i, p_num-1);*/ - return i; - } - } + p_num++; - p_num++; + if ((p_num + 1) >= PARRAY_SIZE) { + fprintf(stderr, "*** Bogus attempt to %s() past end of parray " + "***\n", __func__); + } - if (p_num+1 >= PARRAY_SIZE) { - fprintf(stderr, "*** Bogus attempt to get_empty_slot() past end of parray ***\n"); - } + parray[p_num - 1].status = PLAYER_EMPTY; -/*** fprintf(stderr,"New player added in parray[%d]\n", p_num-1); */ - parray[p_num - 1].status = PLAYER_EMPTY; - return p_num - 1; + return (p_num - 1); } PUBLIC void -- cgit v1.2.3