Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write program in C: You cannot make any assumptions about the maximum length for a word, so you must allocate space for each word as

Write program in C:
You cannot make any assumptions about the maximum length for a word, so you must allocate space for each word as well as for the node.
A word is a maximal string of digits, letters, and underscores.
When you print your words, print the count in the first 5 spaces then a blank, and then the word. In other words, use the format string "%5d % s".
Here is an example input and output. Suppose the following is the preamble to the United States Declaration of Independence, and is in the file "declindep":
The unanimous Declaration of the thirteen united States of America,
When in the Course of human events, it becomes necessary for one
people to dissolve the political bands which have connected them
with another, and to assume among the powers of the earth, the
separate and equal station to which the Laws of Nature and of
Nature's God entitle them, a decent respect to the opinions of
mankind requires that they should declare the causes which impel
them to the separation.
Run your program as:
wordsorta declindep
The first 20 lines of your output will be:Write a program that reads words from one or more files named on the command line and prints the words in sorted order (use ASCII ordering), and a count of how many times each word appears in the input. The easiest way to do this is to use a linked list. A node in the list might look like:
struct node {
char *word; /* pointer to word */
int count; /* number of times word occurs */
struct node *next; /* pointer to next entry in linked list */
}
You cannot make any assumptions about the maximum length for a word, so you must allocate space for each word as well as for the node.
A word is a maximal string of digits, letters, and underscores.
When you print your words, print the count in the first 5 spaces then a blank, and then the word. In other words, use the format string "%5d %s".
If your program cannot open a file for reading, print the file name followed by a colon and a space (: ) and then append the system error message. The best way to do this is to use the library function perror(3).
Your program is to return an exit status code that is the number of files named on the command line that could not be opened. So if all files can be opened, the exit status code is 0; if five such files cannot be opened, the exit status code would be 5.
Here is an example input and output. Suppose the following is the preamble to the United States Declaration of Independence, and is in the file declindep:
The unanimous Declaration of the thirteen united States of America,
When in the Course of human events, it becomes necessary for one
people to dissolve the political bands which have connected them
with another, and to assume among the powers of the earth, the
separate and equal station to which the Laws of Nature and of
Nature's God entitle them, a decent respect to the opinions of
mankind requires that they should declare the causes which impel
them to the separation.
Run your program as:
wordsorta declindep
The first 20 lines of your output will be:
1 America
1 Course
1 Declaration
1 God
1 Laws
2 Nature
1 States
1 The
1 When
1 a
1 among
3 and
1 another
1 assume
1 bands
1 becomes
1 causes
1 connected
1 decent
1 declare
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

=+the companys balance? Explain.

Answered: 1 week ago

Question

(Appendix) What are sales returns? Why do sales returns occur? LO86

Answered: 1 week ago