The programs you wrote for Problem Set VII, even though they utilized dynamic memory allocation, had one major shortcoming; you had to establish an array in which to hold the pointers to the memory allocated. This meant that you had to allow for a maximum number of pointers for the structures that were to be used.
There are many occasions in programming when we as programmers have no idea how much data our programs will be asked to handle or how much RAM the machine our program is running on might have (or how much is still available to us because other programs are running). Linked lists of data allow us to use as little or as much memory as necessary (as long as it is available).
Before attempting this problem, read the Dynamic Memory Allocation page. Then save, compile, and trace through the sample program, making sure you understand how the pointers are used.
For the programs below, you are to use the data from Section 69 of Premru's book which I have placed in its entirety on a web site.
Using the following global struct declaration
struct record_s {
char *english,
*italian,
*german,
*slovenian;
struct record_s *nx; };
and these variable declarations in main()
struct record_s *head_record_ptr = NULL; struct record_s *current_record_ptr = NULL;
you are to write a program which reads in the data from Section 69 of Premru's book, sorts it based on the English and writes it out to a file called premru69.eng.
N.B. The data in premru69.dat is encoded in Latin-2 (ISO-8859-2).
Using the declarations given above, cannibalize your source code for Program I and add the following features:
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 7 before exiting.