$29
The Problem Your task is to writ e a program that stores and retrieves structures in a file on disk. The file of structures must remain on the disk once your program ends. You should be able to store structures to the file and retrieve from the file after restarting the program. The record that you will be writing to file has the following structure: struct contact { unsigned long phone_number; long first_name_posn; long last_name_posn; long company_name_posn; long email_posn; long next; }; first_name_posn, last_name_posn, company_name_posn, and email_posn are the position in the file of the First Name, Last Name, Company Name, and Email variable strings. These “locations” will be required for writing and reading the information to be stored. This struct definition cannot be altered in any way. When you write the structures on disk, you will need to store the First Name, Last Name, Company Name, and Email strings separately from the contact structure. In the file you will write the contact structure first followed by the First Name, Last Name, Company Name, and Email strings (if they exist). The only required information is the Phone Number – all other information is optional. The position “next” stores the location in the file where the next contact record is stored. This will function similarly to a linked list data structure, but will use “next” variable to facilitate the linking of records. The file can contain any number of records and associated strings. The name of the file will be myContactList.db (and must match this exactly). If the file does not exist then your program must create it. Interface (input and output) Your program will have an input interface that does the following: Do you wish to enter a new contact (Yes or No)?: First Name: Last Name: Company Name: Phone Number (enter only numbers): Email: The program will move to the next stage when you answer No to the first question. The answer must be No exactly – observe the upper case N and lower case o. The second stage interface is as follows: Do you wish to retrieve a contact (Yes or No)?: Phone Number: The program will end if you answer No to this question. If you answer Yes then it will ask for the phone number of a contact. Your program will search the file for the first record that satisfies this request. If it finds a match, then it will output the following: First Name: Deb Last Name: Stacey Company Name: University of Guelph Phone Number: 5198244120 Email: dastacey@uoguelph.ca If it does not find a match it will output: No match found. In both cases, the interface will continue by going back to the first question - Do you wish to enter a new contact (Yes or No)? The program will create the file myContactList.db in the directory the program is run from if it does not exist upon program start up. If it does exist, then it will be opened for reading and writing and the current file pointer should be positioned at the end of the file. Example Session $ ./contactList Do you wish to enter a new contact (Yes or No)?: Yes First Name: Deb Last Name: Stacey Company Name: University of Guelph Phone Number (enter only numbers): 5198244120 Email: dastacey@uoguelph.ca Do you wish to enter a new contact (Yes or No)?: Yes First Name: Donald Last Name: Duck Company Name: Phone Number (enter only numbers): 4162599373 Email: dduck@disney.com Do you wish to enter a new contact (Yes or No)?: Yes First Name: Last Name: Company Name: Ducks Unlimited Phone Number (enter only numbers): 4162344567 Email: ducks@unlimited.ca Do you wish to enter a new contact (Yes or No)?: No Do you wish to retrieve a contact (Yes or No)?: Yes Phone Number: 4161234456 No match found. Do you wish to enter a new contact (Yes or No)?: No Do you wish to retrieve a contact (Yes or No)?: Yes Phone Number: 4162599373 First Name: Donald Last Name: Duck Company Name: Phone Number: 4162599373 Email: dduck@disney.com Do you wish to enter a new contact (Yes or No)?: No Do you wish to retrieve a contact (Yes or No)?: No $ The file myContactList.db will contain three records (Deb Stacey, Donald Duck, and Ducks Unlimited). The file should be 261 bytes long and the command “od –cd myContactList.db” will produce the following: 0000000 030 351 326 5 001 \0 \0 \0 0 \0 \0 \0 \0 \0 \0 \0 59672 13782 1 0 48 0 0 0 0000020 4 \0 \0 \0 \0 \0 \0 \0 ; \0 \0 \0 \0 \0 \0 \0 52 0 0 0 59 0 0 0 0000040 P \0 \0 \0 \0 \0 \0 \0 e \0 \0 \0 \0 \0 \0 \0 80 0 0 0 101 0 0 0 0000060 D e b \0 S t a c e y \0 U n i v e 25924 98 29779 25441 31077 21760 26990 25974 0000100 r s i t y o f G u e l p h \0 29554 29801 8313 26223 18208 25973 28780 104 0000120 d a s t a c e y @ u o g u e l p 24932 29811 25441 31077 30016 26479 25973 28780 0000140 h . c a \0 315 9 034 370 \0 \0 \0 \0 225 \0 \0 11880 24931 52480 7225 248 0 38144 0 0000160 \0 \0 \0 \0 \0 234 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 0 0 39936 0 0 0 0 0 0000200 \0 \0 \0 \0 \0 241 \0 \0 \0 \0 \0 \0 \0 262 \0 \0 0 0 41216 0 0 0 45568 0 0000220 \0 \0 \0 \0 \0 D o n a l d \0 D u c k 0 0 17408 28271 27745 100 30020 27491 0000240 \0 d d u c k @ d i s n e y . c o 25600 30052 27491 25664 29545 25966 11897 28515 0000260 m \0 w V 030 370 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 109 22135 63512 0 0 0 0 0 0000300 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 342 \0 \0 \0 \0 \0 0 0 0 0 0 226 0 0 0000320 \0 \0 362 \0 \0 \0 \0 \0 \0 \0 005 001 \0 \0 \0 \0 0 242 0 0 0 261 0 0 0000340 \0 \0 D u c k s U n l i m i t e 0 30020 27491 8307 28245 26988 26989 25972 0000360 d \0 d u c k s @ u n l i m i t e 100 30052 27491 16499 28277 26988 26989 25972 0000400 d . c a \0 11876 24931 0 0000405 The data stored is as follows: Contact Record 1: stored at file position 0 • Phone Number: 5198244120 • First Name Position: 48 • Last Name Position: 52 • Company Name Position: 59 • Email Position: 80 • Next: 101 Contact Record 2: stored at file position 101 • Phone Number: 4162599373 • First Name Position: 149 • Last Name Position: 156 • Company Name Position: 0 • Email Position: 161 • Next: 178 Contact Record 3: stored at file position 178 • Phone Number: 4162344567 • First Name Position: 0 • Last Name Position: 0 • Company Name Position: 226 • Email Position: 242 • Next: 261 Other Information Any of the fields can be blank except for Phone Number. If the user does not type anything in these fields, then they will be asked for the information again. E.g. … Phone Number (enter only numbers): Phone Number (enter only numbers): 4162599373 … Coding Guidelines and Testing Assignments which do not compile with your makefile on the SOCS server will receive a grade of 0. You must use the –ansi and –Wall flag. Any changes to the struct definition will result in a grade of 0. Your makefile must produce an executable named contactList. It must be placed inside the bin/ folder. See the Project Structure section for more details. Your submission must be named A3.zip, where is your Central ID. For example, if your username was rdara, you would submit a file name rdaraA3.zip. Sample inputs and expected output/binary file size will be posted within 1 week of the due date. No global variables will be allowed for this assignment. Usage of a global variable will result in an automatic zero for the assignment. Function prototypes and struct definitions are expected to be inside the .h files for your project, and function definitions must be in a file without a main() function (ie. you will need at minimum two .c files and at minimum one .h file) Project Structure Your submission must follow the following structure: src/ bin/ includes/ makefile All required .c files must be placed in the src folder. You must have at least 2 .c files. All .h files required by your solution must be placed in the includes folder. You must have at least 1 .h file. All produced .o files and your executable must be placed in the bin folder. makefile is your functioning makefile. An empty project structure will be uploaded on Courselink for you to use. Any deviations from the expected structure will result in deductions of up to 30%. Your compiled program must be named contactList.