C programming

8. Letter frequency Requirements 1. Write a program that calculates the frequency of letter occurrences in text. 2. Read ASCI 8. Letter frequency Requirements 1. Write a program that calculates the frequency of letter occurrences in text. 2. Read ASCII text from standard input. 3. 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 %.4fn”, letter, freq); 4. Letters that occur zero times should not appear in the output. 5. Characters other than lower and upper case letters should be ignored. 6. 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. 7. The frequencies reported should sum to approximately 1 (with a little slack for accumulation of printf rounding errors). 8. By the way, you cannot implement this function by writing 26 “it” statements (1 for each letter). Hint: Each letter has a numerical ASCII value. Can this numerical value be used at all? Example runs Assume you have named your executable lfreq. The first two example runs show the user entering the text manually in the terminal. The third and fourth runs have text piped in from a file (and the middle of the alphabet is omitted from the output for brevity). A text file happy_prince.txt containing a classic story in English is provided for testing. $ ./lfreg aaab a 0.7500 b 0.2500 $ ./lfreg q 1.0000 ./lfreq



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *