1 Motivation
The goal of this project is to develop a C program making use of C array facilities and looping constructs.
It also presents an opportunity to take advantage of multiple functions within a program.
2 Overview
Your program will work by reading in a set of (possibly repeated) words from the terminal, performing a frequency count on them, and then displaying the five most common words, along with their frequency.
3 Input Specification
Your program will be expected to read words directly from the terminal. Only words will be presented to your program, and the end of the input will be indicated by the ’word’ zzzzz. This end-of-input word should not be included in your frequency count.
For our purposes, a ’word’ will be defined as a contiguous set of no more than twenty lowercase letters.
Neither numbers nor punctuation marks will be present in the input set. No more than 200 unique words will be present in the input set nor will more than 500 words total be presented. There are guaranteed to be a minimum of five unique words. Any number of whitespaces, including spaces, tabs, and newlines, may appear between words, and should be ignored.

4 Output Specification
Your program is to print out the five most frequently-occuring words, along with their frequencies. Words with the same frequency should be presented in alphabetical order. Your program need not print an input prompt, but your output should be neatly formatted.
5 Program Requirements
For this program, you must make use of at least one (useful) function in addition to main(). The precise nature of this function is up to you. All of your functions should be contained in a single file named freq.c. You may accomplish the sorting however you wish, though a ’stable’ sort algorithm and a bit of thought will make getting the correct ordering pretty easy. qsort() is also an option.

In addition to obeying the above specification, your program must also satisfy the following requirements:
• You must make use of at least one array. (You probably need at least two.)
• You may not make use of any global variables for this assignment. All variables must be either defined within functions or passed as parameters.
• You may, but are not required to, make use of one or more structures.
• Your code is well-formatted, adequately commented, and free of glaring inefficiencies.
• Your code compiles without warning or error using the -std=c99 and -pedantic flags.
• Your program must compile and run without any error in WSU lab computers.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

Program which computes the 5 most frequent words from the standard input

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_WORD_LENGTH 21
#define MAX_TOTAL_WORDS 200

// stores the word and its frequency
typedef struct
    char word[MAX_WORD_LENGTH];
    int frequency;
} word_entry;

// updates the array of entries with the new word
// entries: list of word_entry elements
// count : total number of words so far
// word   : a new word
void update_entries(word_entry *entries, int *count, char *word)
    // search for the word if it appeared before on the input
    for (int i=0; i<*count; i++)
       if (strcmp(entries[i].word...

By purchasing this solution you'll be able to access the following files:

for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats