![]() |
VOOZH | about |
A Contact Book is a simple application to store and manage people's contact information such as names and phone numbers. We will create a simple console-based C contact book in this project.
Our contact book application will have following features:
To do this project, the programmer must be familiar with the following C concepts:
Additionally, we will need a working C development environment to create and test the application. Refer to this if you want to revise - C Tutorial
Let's start working on this project:
STEP 1: Basic Setup
First, we need to create some variables to store the data such that they are accessible to whole program. For this purpose, we use global variables.
We also created a constant macro MAX to specify the maximum number of contacts it can store.
STEP 2: Creating "Add New Contact" Feature
In this step, we create a function that can add contact to the parallel arrays. While adding contact, we also make sure that the given number is valid.
The fgets() is used to read the full string (including spaces).
STEP 3: Display All Contacts
We just need to iterate through both the arrays simultaneously and print the contacts one by one.
STEP 4: Search by Name
To find the matching name, we use strcmp() function with the target name and all the names in the names[] array. We have used recursion to implement this, but it can also be implemented using iteration.
The extra argument index is used to change the search element in each recursive call.
STEP 5: Recursive Search by Phone
Similar to search by name, the search by phone feature can be implemented.
STEP 6: Delete Contact by Name
We cannot actually delete an element in arrays, so we have to implement a workaround.
STEP 7: Dashboard
The final step is to create a dashboard or a menu using which the user can use this application. It should provide options to select all the functionality. You can also add desired cosmetic elements to improve readability and accessibility.
In the above menu, an infinite loop is used to make the application run until the user wants to exit.
Combining each of these elements, we get the executable source code:
On executing this code, we get the following output: