Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program that calculates the frequency of letter occurrences in text. Read ASCII text from standard input. On reaching EOF, print to stdout the
- Write a program that calculates the frequency of letter occurrences in text.
- Read ASCII text from standard input.
- On reaching EOF, print to stdout the normalized frequency of occurrence for each letter a-z that appeared in the input, one per line, in alphabetical order using the format produced by
printf( "%c %.4f ", letter, freq);
- Letters that occur zero times should not appear in the output.
- Characters other than lower and upper case letters should be ignored.
- Lower and upper case instances count as the same letter, e.g. 'a' and 'A' are both reported for the letter 'a' on the output.
- The frequencies reported should sum to approximately 1 (with a little slack for accumulation of printf rounding errors).
- By the way, you cannot implement this function by writing 26 "if" statements (1 for each letter). Hint: Each letter has a numerical ASCII value. Can this numerical value be used at all?
Example Runs:
$ ./lfreq aaab a 0.7500 b 0.2500
$ ./lfreq q q 1.0000
./lfreq < happy_prince.txt a 0.0841 b 0.0140 c 0.0206 ... y 0.0240 z 0.0002
$ ./lfreq < "large novel in English.txt" a 0.0817 b 0.0149 c 0.0278 ... y 0.0197 z 0.0001 Language is C. Please avoid the use of break and continue.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started