X-Git-Url: https://git.cworth.org/git?p=mnemon;a=blobdiff_plain;f=mnemon.c;h=1eebd20df491681e42a21190451ec55116f3893b;hp=c0efa6902e50281e91a5d4cc699ab40a6041bd70;hb=698b08fa45715b2d24f311c041f3858decbd21d6;hpb=640321106d0b60f1f9ed408537691b90a768a651 diff --git a/mnemon.c b/mnemon.c index c0efa69..1eebd20 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) { @@ -627,12 +637,16 @@ mnemon_do_challenges (mnemon_t *mnemon) printf ("%s\n", item->challenge); response = readline ("> "); - if (response == NULL) + if (response == NULL) { + printf ("\n"); break; + } 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 +674,7 @@ main (int argc, char *argv[]) { mnemon_t mnemon; - srand (time (NULL)); + srand (1); mnemon_init (&mnemon);