Great Deal! Get Instant $25 FREE in Account on First Order + 10% Cashback on Every Order Order Now

HW2 CS240 - Programming in C HOMEWORK 2 ——————————————————————————————————————————————————————————————————————————————— Write a C program to implement the following requirement: Input: The program...

1 answer below »

HW2
CS240 - Programming in C
HOMEWORK 2
———————————————————————————————————————————————————————————————————————————————
Write a C program to implement the following requirement:
Input:
The program will read from the standard input any text up to 10,000 characters.
Output:
The program will sort the words in alphabetical order and print to the standard
output:
On the first line, the sorted words separated by a comma “,”.
On the second line, the index of the sorted words separated by a comma “,”. The
index start from 0.
If two words are the same, the smaller index will appear first.
(A word is a string without whitespaces (space/ta
new line character))
———————————————————————————————————————————————————————————————————————————————
Note: If the input text is empty or there is no word in the input text, the
program must print the empty string to stdout.
———————————————————————————————————————————————————————————————————————————————

Requirements:
Use the following struct to store the word and its index:
struct WORD {
char *s;
int index;
}
You MUST use pointer to do the sorting. If you don’t use pointer, you will get 0.
Page / 1 2
CS240 - Programming in C
SAMPLE INPUT 1
hello World! 123
SAMPLE OUTPUT 1
123,hello,World!
2,0,1
———————————————————————————————————————————————————————————————————————————————
SAMPLE INPUT 2
empty>
SAMPLE OUTPUT 2
empty>
———————————————————————————————————————————————————————————————————————————————
SAMPLE INPUT 3
This is the 1ST line.
This is the 2ND line.
SAMPLE OUTPUT 3
1ST,2ND,is,is,line.,line.,the,the,This,This
3,8,1,6,4,9,2,7,0,5
Page / 2 2
Answered 3 days AfterFeb 24, 2022

Solution

Savita answered on Feb 28 2022
29 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here