Professional Documents
Culture Documents
BLDEA
BLDEA
HALAKATTI COLLEGE OF
ENGINEERING AND TECHNOLOGY
VIJAYAPUR – 586103
BACHELOR OF ENGINEERING
IN
INFORMATION SCIENCE & ENGINEERING
This program provides a basic example of managing a phone book using a linked list
in C. However, it lacks error handling and input validation, which would be important
considerations for a production-level application.
The objectives of this phone book application program include:
1. Data Organization:
Utilize a linked list data structure to organize and store phone book
entries.
Each entry consists of a name, phone number, and a pointer to the next
entry in the linked list.
2. User Interaction:
Provide a user-friendly interface through the console, allowing users to
interact with the phone book application.
Display a menu with options for adding, deleting, modifying phone
numbers, displaying entries, and exiting the program.
3. Entry Manipulation:
Allow users to add new phone book entries by providing a name and
phone number.
Provide the capability to delete entries based on the provided name.
Allow users to modify the phone number of an existing entry.
4. Display Functionality:
Implement a function to display all entries in the phone book,
providing users with an overview of the stored information.
5. Memory Management:
Dynamically allocate memory for each phone book entry to
accommodate a variable number of entries.
Properly free allocated memory when entries are deleted or when the
program exits to prevent memory leaks.
6. Error Handling:
Provide appropriate feedback to the user if an entry is not found during
deletion or modification.
Handle invalid user input by displaying error messages and prompting
the user to enter valid information.
7. User Experience:
Offer a simple and intuitive user experience, allowing users to perform
common phone book operations easily.
8. Graceful Exit:
Allow users to exit the program in a controlled manner, freeing all
allocated memory before terminating.
9. Documentation and Output:
Include informative output messages to guide the user through each
operation.
Display the phone book entries in a readable format for user
convenience.
Overall, the program aims to create a functional and interactive phone book
application that allows users to manage, view, and modify their contacts efficiently.
The phone book application uses a linked list data structure to manage phone book
entries. Below is an explanation of the methodology used for each function in the
program:
1. Structure Definition:
struct PhoneBookEntry: Defines the structure of a phone book entry with
fields for name, phone number, and a pointer to the next entry in the
linked list.
2. createEntry Function:
Objective: Allocate memory for a new phone book entry and initialize
its fields.
Methodology:
Uses malloc to dynamically allocate memory for a new
PhoneBookEntry structure.
Copies the provided name and phone number into the newly
created entry.
Sets the next pointer to NULL.
Returns the pointer to the newly created entry.
3. addEntry Function:
Objective: Add a new entry to the phone book.
Methodology:
Calls the createEntry function to create a new entry with the
provided name and phone number.
Inserts the new entry at the beginning of the linked list by
updating the next pointer of the new entry to point to the
current head of the list.
Updates the head of the list to point to the new entry.
4. deleteEntry Function:
Objective: Delete an entry from the phone book.
Methodology:
Traverses the linked list to find the entry with the specified
name.
If the entry is not found, prints an error message and returns.
If the entry is found, adjusts the pointers to skip the entry in the
linked list.
Frees the memory allocated for the deleted entry.
5. modifyEntry Function:
Objective: Modify the phone number of an existing entry.
Methodology:
Traverses the linked list to find the entry with the specified
name.
If the entry is not found, prints an error message and returns.
If the entry is found, updates the phone number field with the
provided new phone number.
6. displayEntries Function:
Objective: Display all entries in the phone book.
Methodology:
Traverses the linked list and prints the name and phone number
of each entry.
Displays a message if the phone book is empty.
7. freePhoneBook Function:
Objective: Free the memory allocated for the entire phone book.
Methodology:
Traverses the linked list, freeing the memory for each entry.
Uses two pointers ( current and next) to ensure proper traversal
and deallocation.
8. main Function:
Objective: Implement the user interface and control flow for the phone
book application.
Methodology:
Uses a do-while loop to display a menu of options and prompt
the user for their choice.
Calls the appropriate function based on the user's choice.
Continues until the user chooses to exit.
Overall, the methodology involves creating, modifying, and deleting phone book
entries using a linked list, ensuring proper memory management throughout the
program. The user interacts with the application through a menu-driven interface.
INTRODUCTION
The provided program is a simple console-based phone book application implemented in C.
It allows users to manage a phone book by performing operations such as adding new
entries, deleting entries, modifying phone numbers, and displaying the existing entries. The
application employs a linked list data structure to organize and store phone book entries,
providing a dynamic and flexible approach for managing contacts.
Usage Instructions:
1. Users are prompted with a menu offering options to add, delete, modify,
display entries, or exit the program.
2. For adding an entry, users input a name and phone number.
3. To delete an entry, users specify the name of the entry to be removed.
4. Modifying an entry involves providing the name of the entry to be modified
and the new phone number.
5. Displaying entries shows a list of all current contacts in the phone book.
6. The program allows users to exit gracefully, freeing allocated memory.
Educational Value:
1. Educational Purpose:
This project is likely created for educational purposes,
especially for students learning C programming and data
structures. It serves as a hands-on example for practicing
concepts such as structures, linked lists, dynamic memory
allocation, and user input handling.
2. Fundamental Data Structures:
The use of a linked list for storing phone book entries
demonstrates a fundamental data structure. Linked lists offer
flexibility in managing dynamically changing data, making them
suitable for scenarios where the number of entries can vary.
3. Introduction to Dynamic Memory Allocation:
The project introduces the concept of dynamic memory
allocation using the malloc function to create new phone book
entries. This is a crucial aspect of managing memory efficiently
in C programs.
4. Basic User Interaction:
The program provides a simple command-line interface with a
menu-driven system. Users can interact with the phone book
by adding, deleting, modifying entries, and displaying the
current list.
5. CRUD Operations:
The application covers basic CRUD (Create, Read, Update,
Delete) operations commonly found in database and
information management systems. Users can create, view,
update, and delete phone book entries.
6. Error Handling and User Guidance:
The program includes basic error handling to notify users when
an operation fails, such as attempting to delete or modify an
entry that does not exist. User-friendly prompts guide the user
through the menu options.
7. Memory Management:
The inclusion of a function to free allocated memory
(freePhoneBook) demonstrates good programming practice by
preventing memory leaks.
8. Structured Programming:
The code is well-structured, using functions for specific tasks,
enhancing readability, and facilitating code maintenance.
9. Project Expansion:
This project can serve as a foundation for further expansion and
enhancement. Additional features, such as searching for entries,
sorting, or saving/loading data from a file, could be
implemented to make the phone book more sophisticated.
10.Potential Real-World Application:
While this project is a basic example, similar principles can be
applied to real-world applications, such as contact
management systems or small-scale databases.
Usage Instructions:
7. Users are prompted with a menu offering options to add, delete, modify,
display entries, or exit the program.
8. For adding an entry, users input a name and phone number.
9. To delete an entry, users specify the name of the entry to be removed.
10. Modifying an entry involves providing the name of the entry to be modified
and the new phone number.
11. Displaying entries shows a list of all current contacts in the phone book.
12. The program allows users to exit gracefully, freeing allocated memory.
Educational Value: