Question
Write a contacts List App with C language and contains a makefile Write a program in C language that stores and retrieves structures in a
Write a contacts List App with C language and contains a makefile
Write a program in C language 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 be reading the information to be stored.
When you write the structures on the 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. The file can contain any number of records and associated strings.The name of the file will be myContactList.db and 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 Noto 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 Noto 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: Jack
Last Name: Steves
Company Name: Jacks Business
Phone Number (enter only numbers): 6044015214
Email: JackS mal.com
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 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
$ ./contacts
Do you wish to enter a new contact (Yes or No)?: Yes
First Name: Jack
Last Name: Steves
Company Name: Jacks Business
Phone Number (enter only numbers): 6044015214
Email: jackS mal.com
Do you wish to enter a new contact (Yes or No)?: Yes
First Name: William
Last Name: Wilson
Company Name: Wilsons Sport Company
Phone Number (enter only numbers): 8008745930
Email: Wilson wilson.com
Do you wish to enter a new contact (Yes or No)?: Yes
First Name:
Last Name:
Company Name: Sports equipment
Phone Number (enter only numbers): 9187189876
Email: Sport equip.com
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: 8008855930
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: 8008745930
First Name: William
Last Name: Wilson
Company Name: Wilsons Sport Company
Phone Number (enter only numbers): 8008745930
Email:wilson wilson.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 myContactsList.db will contain three records (Deb Stacey, Donald Duck, and Ducks Unlimited).The file should be 261 bytes long and the command od cd myContactsList.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 048 0 0
00000020 4 \0 \0 \0 \0 \0 \0 \0 ; \0 \0 \0 \0 \0 \0 \0
52 0 0 0 59 0 0
00000040 P \0 \0 \0 \0 \0 \0 \0 e \0 \0 \0 \0 \0 \0 \0
80 0 0 0 101 0 0
00000060D e b\0 J a c k\0 B u I
2592498 29779 25441 31077 21760 26990 25974
0000100r n e s s c o m p a n y\0
29554 29801 8313 26223 18208 25973 28780 104
0000120 g m a I l c o m24932 29811 25441 31077 30016 26479 25973 2878
00000140h . c a\0 315 9 034 370\0\0\0\0 225\0\011880 24931 524807225 248 0 38144
00000160 \0\0\0\0\0 234\0\0\0\0\0\0\0\0\0\00 0 39936 0 0 0 0
00000200 \0\0\0\0\0 241\0\0\0\0\0\0\0 262\0\00 0 41216 0 0 0 45568 00000220 \0\0\0\0\0 W I l s o n\0 c o m p a n y 0 17408 28271 27745 100 30020 27491
0000240 \0 d s p o r t
25600 30052 27491 25664 29545 25966 11897 28515
0000260m\0 w V 030 370\0\0\0\0\0\0\0\0\0\0109 22135 63512 0 0 0 0 00000300 \0\0\0\0\0\0\0\0\0\0 342\0\0\0\0\00 0 0 0 0 226 0
00000320 \0\0 362\0\0\0\0\0\0\0 005 001\0\0\0\00 242 0 0 0 261 0
00000340 \0\0 s p o r t e q u i e0 30020 274918307 28245 26988 26989 25972
0000360d\0 s p o r t e q u I p100 30052 27491 16499 28277 26988 26989 25972
0000400d . c a\0 11876 24931 0 0000405
The data stored is as follows:
Contact Record 1: stored at file position 0
Phone Number: 6044015214
First Name Position: 48
Last Name Position: 54
Company Name Position: 60
Email Position: 82
Next: 95
Contact Record 2: stored at file position 95
Phone Number: 8008745930
First Name Position: 126
Last Name Position: 135
Company Name Position: 145
Email Position: 161
Next: 179
Contact Record 3: stored at file position 178
Phone Number: 9187189876
First Name Position: 0
Last Name Position: 0
Company Name Position: 198
Email Position: 226
Next: 234
Other Information
Any of the fields can be blank except for Phone Number and Email. If the user does not type anything in these fields, then they will be asked for the information again.
Once those done, there will be some more advanced requirements upon those.
You must enter either the Last Name or a Company Name for each contact (as well as the phone number and email).
You must check that the phone number has either 7 or 10 digits.
The email address must have the following format: xxx@xxx.xxx
Your interface will allow the following to be done:
1. List all contacts inalphabetical (ascending) order by name (either last name or company name)only displaying the name. Only 5 names will be displayed at a time. You can tell the interface to scroll down or up one name at a time.
2. Add a new contact.
3. Allow one of the contacts to be selected(by the number beside it on the display).
4. Display the full information for the selected contact.
5. Change the phone number or email for a selected contact.
6. Delete a selected contact.
7. Return to the full contacts list.8.Exit the program (all changes to the myContactsList.db file must be written to disk).
Interface The "full contacts list" interface is as follows: Number of Contacts 20 1. Aberfoyle Mill 2. Air Canada 3. Jason Argonaut 4. Terry Bernard 5. Bombay Caf Action The action inputs are the following Move down one name Move up one name Number Select this contact and display its full information Add a new contact Exit the program The following pages will introduce the three different interfaces 1. Full Contacts List Contact information-Display 2. 3. Contact Information Edit and Add
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started