Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

The output is actually missing one hi -2 at the end before mark - 1

 

**Section 5.20 - CIS 161: Introduction to C Programming - LAB: Word Frequencies**

### Objective:
The aim of this lab is to write a C program that reads a series of words and outputs the frequency of each word.

### Instructions:
- Develop your program and test it as much as you need. 
- Submit the final version before the deadline.

### Code Details:
A skeleton code is provided with the following functionality:
- Read input string.
- Count and store frequencies of each word.
- Print the words and their respective frequencies.

```c
#include <stdio.h>
#include <string.h>
#define MAX_WORDS 50
#define MAX_WORD_LENGTH 50

int main() {
    char words[MAX_WORDS][MAX_WORD_LENGTH];
    int frequencies[MAX_WORDS];
    int numWords = 0;
    char input[200];

    fgets(input, 200, stdin);

    // Split the input string into words
    char *token = strtok(input, " \n");
    while (token != NULL) {
        int found = 0;
        for (int i = 0; i < numWords; i++) {
            if (strcmp(words[i], token) == 0) {
                frequencies[i]++;
                found = 1;
                break;
            }
        }
        if (!found) {
            strcpy(words[numWords], token);
            frequencies[numWords] = 1;
            numWords++;
        }
        token = strtok(NULL, " \n");
    }

    // Output the words and frequencies
    for (int i = 0; i < numWords; i++) {
        if (frequencies[i] != 0) {
            printf("%s - %d\n", words[i], frequencies[i]);
        }
    }

    return 0;
}
```

### User Interface:
- **Develop mode:** Allows you to write and test your code.
- **Submit mode:** Submit the final version of your code for grading.
  
### Input and Output:
1. **Enter Program Input (optional):**
   - Example: `5 hey hi Mark hi mark`

2. **Run Program:**
   - Click to execute the code and observe the program's output.

3. **Program Output Displayed Here:**
   - The area where the result of running the program will be displayed.
  
### Example:
#### Input:
```
5 hey hi Mark hi mark
```
expand button
Transcribed Image Text:**Section 5.20 - CIS 161: Introduction to C Programming - LAB: Word Frequencies** ### Objective: The aim of this lab is to write a C program that reads a series of words and outputs the frequency of each word. ### Instructions: - Develop your program and test it as much as you need. - Submit the final version before the deadline. ### Code Details: A skeleton code is provided with the following functionality: - Read input string. - Count and store frequencies of each word. - Print the words and their respective frequencies. ```c #include <stdio.h> #include <string.h> #define MAX_WORDS 50 #define MAX_WORD_LENGTH 50 int main() { char words[MAX_WORDS][MAX_WORD_LENGTH]; int frequencies[MAX_WORDS]; int numWords = 0; char input[200]; fgets(input, 200, stdin); // Split the input string into words char *token = strtok(input, " \n"); while (token != NULL) { int found = 0; for (int i = 0; i < numWords; i++) { if (strcmp(words[i], token) == 0) { frequencies[i]++; found = 1; break; } } if (!found) { strcpy(words[numWords], token); frequencies[numWords] = 1; numWords++; } token = strtok(NULL, " \n"); } // Output the words and frequencies for (int i = 0; i < numWords; i++) { if (frequencies[i] != 0) { printf("%s - %d\n", words[i], frequencies[i]); } } return 0; } ``` ### User Interface: - **Develop mode:** Allows you to write and test your code. - **Submit mode:** Submit the final version of your code for grading. ### Input and Output: 1. **Enter Program Input (optional):** - Example: `5 hey hi Mark hi mark` 2. **Run Program:** - Click to execute the code and observe the program's output. 3. **Program Output Displayed Here:** - The area where the result of running the program will be displayed. ### Example: #### Input: ``` 5 hey hi Mark hi mark ```
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education