CSE 333 21wi Exercise 5

out: Wednesday, January 27, 2021
due: Monday February 1, 2021 by 10:00 am

Exercise Goals

Setup

Do a git pull and find directory ex05/. Copy file state-machine.c to ex05.c. You'll implement your code by modifying ex05.c.

Description

ex05/ contains two solutions to the "vowels in order" problem discussed in class. Modify file ex05.c, which is an implementation of the state machine approach, in two ways:

  1. Instead of printing all words that have all five vowels in order, print only words that have all five vowels in order and no other vowels in them. For instance, the word "unabstentious" has all five vowels in order, and so would be printed by the state-machine code, but it should be rejected by your code because of the initial 'u'. On the other hand, the word "bacterious" would be printed by state-machine and by your code.
  2. state-machine.c declares (and defines) a fixed array of length 100 characters to buffer words that might need to be printed. If a word is longer than that, it won't be printed correctly. Modify the implementation to dynamically resize the array as needed. Start by allocating an array of length 2. Whenever you need to add a character to the word but the array is too small, allocate a new array that is double the size of the existing array and use it instead. Don't leak memory. Don't mangle words.

    (An initial size of 2 characters may sound ridiculously small, and it is. For the purposes of this exercise, start with that size anyway. The technique of allocating some fixed size and replacing with something twice as big is a common strategy for dynamically resized arrays. Using that scheme, the number of reallocations required in any execution is about the log of the maximum size encountered during execution, and the amount of space in use for the array is within a factor of 2 of the minimal amount required by that execution.)

Turn-In

You should tag your code ex05-final and push to your repository. We will test your implementation using our own data file. We expect that the command gcc -std=c17 -Wall -O3 ex05.c -o ex05 will build your application, and that ./ex05 < our-file.txt will cause it to process our-file.txt. We may also look at your source code.