These are the first of several problems which involve the use of dynamically allocated memory. For full marks, you must not only use malloc() to obtain RAM for data storage, you must also ensure that all allocated memory is freed before the program terminates. You must provide hard copy and ask the teacher to run your program.
Using the following compiler directive and variable declarations
#define MAXNAMES 20 char *names[MAXNAMES]; char name[80]; int numnames = 0; int i; FILE *fpin; char infile[80];
write a program which will read in a list of newline-terminated strings, each of which consists of the name of a member of your class. Each name is to be stored in a separately allocated part of RAM. The newline character is not to be stored.
Your program must follow the pseudocode provided below.
N.B. A graceful exit from the program is required if the user-specified file does not exist. For this quickie program, you may assume that the memory requested is in fact allocated.
Using the compiler directive and variable declarations given above for Program I, write a program which will read from a file a list of newline-terminated strings, sort them in ascending alphabetic order, print the new sorted list and write the sorted list to a file whose name is created from the name of the input file by appending .sorted, e.g. list --> list.sorted.
You can adapt any of the following sorting algorithms for your program:
Your program must follow the pseudocode provided below.
N.B. A graceful exit from the program is required if the user-specified file does not exist. For this program, you must ensure that the memory requested is in fact allocated -- if it is not, you must call the function described in Step 8 before exiting.