X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=mnemon.c;h=5ce736433eed2cff4c931dde86a39c490f8f15f0;hb=bc28e389a7758c1450a90bf5290ba216d5ea1abe;hp=4c5acd26287ce381e13a25efa86c81eb800536da;hpb=d23b1556222ac75ac486f187b20e8022ddb5dc30;p=mnemon diff --git a/mnemon.c b/mnemon.c index 4c5acd2..5ce7364 100644 --- a/mnemon.c +++ b/mnemon.c @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -730,6 +731,7 @@ mnemon_save (mnemon_t *mnemon) category_print (category, file); + fsync (fileno (file)); fclose (file); err = rename (lock_filename, filename); @@ -1151,7 +1153,8 @@ mnemon_do_challenges (mnemon_t *mnemon) while (1) { if (category->time_limit > 0.0) { - readline ("The next one is timed. Press enter when ready:"); + response = readline ("The next one is timed. Press enter when ready:"); + free (response); } printf ("%s\n", item->challenge); @@ -1166,10 +1169,12 @@ mnemon_do_challenges (mnemon_t *mnemon) return; } - if (response[0] == '/') + if (response[0] == '/') { mnemon_handle_command (mnemon, response + 1); - else + free (response); + } else { break; + } } mnemon_handle_response (mnemon, bin, item_index, @@ -1177,17 +1182,17 @@ mnemon_do_challenges (mnemon_t *mnemon) (end.tv_sec + end.tv_usec / 1e6) - (start.tv_sec + start.tv_usec / 1e6), category->time_limit); + free (response); } while (mnemon->to_introduce || mnemon->unlearned || mnemon->to_master > 0); - - printf ("Great job.\n"); } int main (int argc, char *argv[]) { mnemon_t mnemon; + char *response; srand (time (NULL)); @@ -1201,5 +1206,15 @@ main (int argc, char *argv[]) mnemon_fini (&mnemon); + mnemon_init (&mnemon); + mnemon_load (&mnemon); + + printf ("Great job.\nHere are your current results:\n"); + mnemon_print_histogram (&mnemon, NULL, 0); + response = readline ("Press enter to quit.\n"); + free (response); + + mnemon_fini (&mnemon); + return 0; }