This is the second in the series of assignments that interact with genealogy files. You are to write a program that reads a GEDCOM file into two sorted arrays of structs, and then permits searching for the children of a named person as in p7. This time there will be one type of struct named Individual, that contains information about an individual, and another type of struct named Family, that contains information about a family. Besides all of the information from the two arrays of p7, the two structs contain additional information that facilitates searching using binary search. Despite these changes, the output will be identical to that of p7.
Though the two arrays of structs are a different way of storing the information of p7’s four arrays, the tasks of parsing the file will not be dramatically different. However, because the struct arrays will be sorted, the accessing routines will be different. On the bright side, you will not have to write sorting and binary searching routines. Instead, you will be calling the qsort() and bsearch() functions of stdlib.h to do these chores.
Though it will involve many changes, I suggest you start with either your or my p7 code, and then modify it. You are welcome to use my p7 code without fear of accusations of plagiarism. You will note that there are fewer specifications for this assignment than in the past. It is time for you to develop a program on your own. However, I will give suggestions and guidance for dealing with the structs and stdlib functions.
Specifications:
All information unique to an individual must be stored in a struct of type Individual that is typedeffed in main.h.
Individual information must include INDI (the individual’s ID), name, FAMC (ID of family for which the individual is a child), and FAMS (ID of family for which the individual is a spouse).
There will be a dynamically allocated array of Individual structs that will sorted by IDs.
All information about a family must be stored in a struct of type Family that is typedeffed in main.h.
Family information must include FAM (the family’s ID), HUSB, WIFE, chil_count (the number of children, an int), and CHILs as a dynamically allocated array of IDs based on the number of children. Note that the CHILs array differs from p7 in that it is a char** (a dynamic array of dynamically allocated char arrays) instead of a dynamically allocated array of chars.
read_family() must call a new function named add_child() that will take a char* line, and a Family* that is a pointer to a single Family (not an array of Family). add_child() will create a new char** array one larger than the current CHILs to handle the additional child. There must not be a memory leak in add_child().
There will be a dynamically allocated array of Family structs that will be sorted by IDs.
All remaining dynamic memory must be freed in deallocate().
Since all the variables in the structs, except CHILs and chil_count, have a one-to-one relationship with the tags in the files, you may use the uppercase tags for the variable names, e.g. FAMS and FAMC. All of the variables of the structs will be dynamically allocated char*, except CHILs and chil_count.
find_children() must call a new function named print_children() that prints the names of all the children in a specific family. print_children() must have three parameters: a Family* that is a pointer to a single Family (not an array of Family), the individuals array, and individual_count.
To use both qsort() and bsearch(), you will need to write two compare functions that can compare pointers of Individuals or Family structs, and return an int based on comparing their respective IDs, similar to those returned by strcmp(). (Hint: not only “similar”, but actually identical.)
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.