out: Wednesday, January 27, 2021
due: Monday February 1, 2021 by 10:00 am
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
.
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:
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.
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.)
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.