Skip to content

Select a random joke at startup

David G. Martin IV requested to merge random into master
  • Refactor reused code into functions (DRY)
  • Close files at shutdown in addition to unmapping them
  • Pick a random joke at startup

The program still runs through the list of jokes in order, but now starts randomly somewhere in the middle of the file.

This requires parsing the file twice; once to count the jokes, then again to store pointers to them after allocating an appropriately large array.

It would be possible to guess at the initial array size and adjust it as we parse the file, but that is arguably more complicated and has minimal benefit on the small list of jokes we will work with IMO.

Merge request reports

Loading