Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Binary Files and Structures on Disk in language = C /* please leave comments */ PLEASE DONT JUST COPY PASTE ANOTHER CHEGG ANSWER, LOOKING FOR

Binary Files and Structures on Disk in language = C /* please leave comments */ PLEASE DONT JUST COPY PASTE ANOTHER CHEGG ANSWER, LOOKING FOR NEW ALTERNATIVE

I need 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.

(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

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: Ryan

Last Name: Wong

Company Name: IBM

Phone Number: 5543549686

Email: ryanwong@IBM.com

If it does not find a match it will output:

No match found

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

The file should also be 261 bytes long

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions