Starting from:

$30

COM1002 Lab 9 -Solved

Task: Given N, the total number of names, and the set of names following N; make a dynamic memory alloca9on and store these names in the allocated memory. (You may assume that name lengths will not exceed 30 characters.) Then, sort the given names within in your memory and print the sorted name list.  

•       Print the names in descending order, i.e. the reverse of the dic9onary order.  

•       The names can contain small or capital leEers; you need to represent all the characters in a name in small leEers first (before sor9ng). i.e. john marie jack etc.

Input format: [S] stands for a Space character 

<N: number of names>[‘\n’] 

<Name 1>[S]<Name 2>[S] … <Name N> 

Output Forma_: Name_A<i> below shows the i’th name in the descending ordered name set.

< Name A1>’\n’ 

< Name A2>’\n’ 

… 

< Name AN>’\n’ 

Example Input: 

3  

boB aNNie John

Output: 

john bob annie

Hints: 

You can include <string.h> file and use related string func9ons if you need them.

TesSng: 

No test files will be provided for this quiz. Test your programs with your own test files while developing your program.  

As usual, use input redirec3on mechanism of your opera9ng system to test your programs. For example, if your executable is called as Lab9, redirect the input.txt file to standard input using < operator and redirect your outputs to a file using > operator such as:

> ./Lab9<input.txt>output.txt 

This kind of execu9on enables your programs to read inputs from a file without wri9ng any file related func9ons (e.g. fopen(), fscanf() etc.). In other words, the getchar() or scanf() func9ons in your code reads data from the redirected files instead of the std. input in this way (e.g. keyboard).

More products