From: Carl Worth Date: Tue, 17 Apr 2007 18:12:27 +0000 (-0700) Subject: Remove a bin when it becomes empty. X-Git-Url: https://git.cworth.org/git?p=mnemon;a=commitdiff_plain;h=c99ea4af83e849df05018d4e72121f8f73de8bd2 Remove a bin when it becomes empty. Otherwise, mnemon gets stuck repeatedly asking about stale items that aren't really in empty bins. --- diff --git a/mnemon.c b/mnemon.c index c0efa69..67b5889 100644 --- a/mnemon.c +++ b/mnemon.c @@ -379,6 +379,16 @@ mnemon_get_bin (mnemon_t *mnemon, return bin; } +static void +mnemon_remove_bin (mnemon_t *mnemon, + bin_t *bin) +{ + int i = bin - mnemon->bins; + + memmove (bin, bin + 1, (mnemon->num_bins - i) * sizeof (bin_t)); + mnemon->num_bins--; +} + static void chomp (char *s) { @@ -633,6 +643,8 @@ mnemon_do_challenges (mnemon_t *mnemon) correct = (strcmp (response, item->response) == 0); bin_remove_item (bin, item_index); + if (bin->num_items == 0) + mnemon_remove_bin (mnemon, bin); if (correct) { printf ("Correct!\n\n"); @@ -660,7 +672,7 @@ main (int argc, char *argv[]) { mnemon_t mnemon; - srand (time (NULL)); + srand (1); mnemon_init (&mnemon);