For this assignment, you will write a program called dg.c
(a “digraph” is a pair of letters).
It will read any number of files, and emit a report about the frequency
of letter pairs in the input.
                
Here are several sample runs. Your output must match exactly, except that the order of the output lines may vary.                 
% cat data Mama misses Papa % c11 -Wall dg.c % ./a.out 1 999 data ma 2 am 1 mi 1 is 1 ss 1 se 1 es 1 pa 2 ap 1 % cat f food % cat d dood % ./a.out 1 99 f d fo 1 oo 2 od 2 do 1 % ./a.out 1 99 d f do 1 oo 2 od 2 fo 1 % cat hitch Don't Panic! % ./a.out 1 1000 hitch do 1 on 1 pa 1 an 1 ni 1 ic 1 % cat now 2024-11-21T06:13:12.262143 % ./a.out 1 1000 now % ./a.out 1500 1000000 ~cs157/pub/hamlet.txt ha 1891 at 1523 er 2105 in 1951 th 3947 he 2991 an 1995 nd 1536 or 1593 ou 1941 % ./a.out 1600 2000 ~cs157/pub/hamlet.txt ha 1891 in 1951 an 1995 ou 1941
Your program must create an array of this type in main
,
and use it to hold the data throughout the program:
                
struct LetterPair { // Note the capital L & P. char first, second; int count; };
struct LetterPair
in any way.
struct LetterPair
type should be declared outside of any function.
main
.
If you encounter “STACK FRAME LINK OVERFLOW”, then try this:
export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a
15 17
then only display digraphs
if their count is 15, 16, or 17.
argv[0]
and go to standard error.
Then, terminate the program—no digraph counts should be produced.
sort -nk2
#define
s are fine).
char
constants for char
values, not int ASCII values:
'A'
, not 65
.
Use web checkin, or:                 
~cs157/bin/checkin HW2 dg.c
Turn in someone else’s work.                 
User: Guest