Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C89 Programming Help! Write a program that sorts a series of words entered by th

ID: 664654 • Letter: C

Question

C89 Programming Help!

Write a program that sorts a series of words entered by the user:

Assume that each word is no more than 20 characters long. Stop reading when the user enters an empty word (i.e., presses enter without entering a word). Store each word in a dynamically allocated string using an array of pointers to keep track of the string, as in the remind2.c program in section 17.2 of your book. After all words have been read, sort the array (using any sorting technique) and then use a loop to print the words in sorted order.

***Use the read_line function to read each word as in remind2.c***

*Please don't just copy and paste someone's code from 2009 in Cprogramming forums, as it's obviously incorrect*

Here's the read_line function:

Explanation / Answer

You need to think how to store an array of words it may be strings or char arrays.

The instructions to be followed is that it should use read_line function, instead of that we wrote a loop that reads 20 characters into a single character array.

we have ignored "stop reading when user enters an empty word" requirement.

a=malloc(n* sizeof(char)); doesn't compile because n is a char array,malloc wants a size.

we are doing to compare strings

Start by creating an array of char pointers to store words:

char *p[WORD_LEN]l (WORD_LEN = 20, max words to read)

This is a loop to allocate a char array of WORD_LIMIT+1,Call read_line to get string.If it is empty exit loop,or else store in next position of an array.

sort the array,need to remember how many strings we read,since it may be less than WORD_LEN.

Get the code to read and print words working first, then do the qsort last.

a = malloc(n * sizeof(char)); doesn't compile because n is a char array, malloc requires a size.We are trying to multiply an address time a constant, which doesn't compile, and doesn't shows any output.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote