Frequency Analysis
In this activity
you will be writing a program
that reads characters from input using getchar()
and counts how many times
each letter of the alphabet appears.
getchar()
will read in the next character from input
and return it.
When it reaches the end of input,
it will return the value EOF
.
You can tell a program
to stop reading characters
by using Ctrl+D,
which will cause getchar()
to return the EOF
value.
You only need to count letters. You don’t need to count numbers or other symbols. You should treat uppercase letters as lowercase letters.
To read from a file
instead of typing in text,
you can use <
.
For example:
$ ./frequencyAnalysis < myTestFile.txt
To tell the program you have finished typing, you can press Ctrl+D.
For example:
$ ./frequencyAnalysis The quick brown fox jumped over the lazy dog Ctrl+D a: 1 b: 1 c: 2 d: 2 e: 4 f: 1 g: 1 h: 2 i: 1 j: 1 k: 1 l: 1 m: 1 n: 1 o: 4 p: 1 q: 1 r: 2 s: 0 t: 2 u: 2 v: 1 w: 1 x: 1 y: 1 z: 1
To run some simple automated tests:
$ 1511 autotest frequencyAnalysis
To run Styl-o-matic:
$ 1511 stylomatic frequencyAnalysis.c Looks good!
You’ll get advice if you need to make changes to your code.
Submit your work with the give command, like so:
$ give cs1511 wk04_frequencyAnalysis
Or, if you are working from home, upload the relevant file(s) to the wk04_frequencyAnalysis activity on Give Online.