QuestionQuestion

Exercises

1. This program randomly combines words contained in its input stream and sends them to the output stream. At program execution, the application shall read in the entire set of words to use during the combination process. After reaching the EOF symbol, the program shall then begin randomly selecting words and combining them into a concatenated output word. By default, the program produces only one combined output word for each execution, but users may change this behavior by providing an optional command line argument (through *argv).
The words the program selects must meet minimum length criteria, and users may also change this value at program execution to meet their needs. The program must accept this.

By default, the program squeezes the words together and omits any spacing between them (e.g., somewhat like this but random), but users may override this behavior with a command line argument as well, and the program will produce output with the user specified parameter.

The command line arguments may appear in any order.
When unable to construct strings meeting the minimum length from the input stream, the program shall alert the user to an error and suggest corrective action.

There shall be no duplicate words in any single output combination, but the same word may appear twice in the total output when producing more than one string (i.e. -n specified >1)
Program Name: crunch
Command Line Args: -d <degree> Number of words from input stream to combine in each crunched output (default =4).
-m <size> The minimum length of each word used (default =6).
-n <count> Number of output strings to produce (default =1).
-s Indicates to insert a space between the output words (default=none).
Program Input: stdin
Program Output: stdout
Return 0 on completion
Allowed Imports: stdio.h stdlib.h time.h

Example Use:
user@computer: $   ./crunch <dict.txt
reducefishersplendidprogram
user@computer: $   ./crunch -s <dict.txt
windows omlette lethargic amount
user@computer: $ ./crunch -n 2 -s<dict.txt
hospitable chicken repair overflow
scrawny belief remain actually

2. Students shall create a program in C which reads ASCII strings from the standard input until it reaches the EOF symbol. From the accumulated input, the program shall extract only its unique tokens, separated by the space character, and send these to the standard output.
For example, if provided with a file containing a text document, it shall send to the standard output every unique word contained therein. The order the words appear in the output does not need to be sorted in any particular order.
The program shall insert a space character between each output word and ignore line endings.
Program Name: unique
Command Line Args: none
Program Input: stdin
Program Output: stdout
Return 0 on completion
Allowed Imports: stdio.h
Example Use:
user@computer: $ ./unique<iamsam.txt

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.

int main(int argc, char** argv) {

    // read from stdin
    char ch; // to store read character
    char word[1024]; // pool
    int index = 0; // index of the read character in pool
    char * words[1024];
    int word_nums[1024];
    int word_num = 0;
    int i;
    int j;
    int matched;

    // read each character
    while (fscanf(stdin, "%c", &ch) != EOF) {
       // add non space character to word
       if (ch != ' ') {
            word[index] = ch;
            index++;
       } else if (index > 0) { // there are some character in to word

            // try to compare the current word to stored words
            for (i = 0; i < word_num; i++) {
                matched = 0;
                // they should have the same length before having the same content
                if (index == word_nums[i]) {
                   matched = 1;
                   // try to find a mismatch
                   for (j = 0; j < word_nums[i]; j++) {
                        if (word[j] != words[i][j]) {
                            matched = 0;
                            break;
                        }
                   }
                }...

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

$53.00
for this solution

or FREE if you
register a new account!

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.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
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