31 32 33 34 35 36 37 38 39 40 41 42) 43 } // Output the words and frequencies for (i = 0; i
31 32 33 34 35 36 37 38 39 40 41 42) 43 } // Output the words and frequencies for (i = 0; i
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
```](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3e035166-c990-4dd0-a7c5-b2c139b07c7d%2F5f282657-c447-41a2-b9e6-88b34d64eb2f%2Fsxq0gol_processed.png&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images

Knowledge Booster
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.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education