Search
The task is to write a simple program that reads a long multiword string with a predefined length. You should parse the string into a new array where the elements are the individual words. The space character is considered the delimiter. Then, use the qsort() function from stdlib.h library to lexicographically sort the words in ascending order. The program prints the sorted words, each on a separate line and terminates cleanly. Uppercase letters should be ordered before lowercase letters.
You will get the standard input of your program as follows
<number of characters> <multiword string>
There will definitely be only a single space character between individual words.
There will be at least one word on the input.
Each word has at least one letter.
Your program is expected to allocate and deallocate used memory properly using malloc(), realloc(), free().
void qsort( void *ptr, size_t count, size_t size, int (*comp)(const void *, const void *) );
You can find testing instances here. Files with the suffix .in contain your input with .out your desired output.
.in
.out
pub00.in
$ cat pub00.in | ./main
25 a bird came down the walk
a bird came down the walk
44 there will be at least one word On the Input
Input On at be least one the there will word
The maximum number of points is 10. No automatic evaluation, as you can test and verify your solution using the provided instances or generate your own.