VOOZH about

URL: https://www.geeksforgeeks.org/c/contact-book-application-using-c/

⇱ Contact Book Application using C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Contact Book Application using C

Last Updated : 23 Jul, 2025

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.

Features

Our contact book application will have following features:

  • Add New Contact: Insert name and phone number into the contact book.
  • Search Contact: Search a contact using recursion, by name or phone number.
  • Display All Contacts: Show all saved contacts.
  • Delete Contact: Remove a contact by name or number.

Project Requirements

To do this project, the programmer must be familiar with the following C concepts:

  • Decision Making and Loops
  • Input/Output and Functions
  • Arrays, Strings and Pointers

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

Implementation

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 create two parallel 2d character arrays: names[i] and phones[i], which together represents one contact.
  • A count integer that keeps track of how many contacts are currently stored.

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.

  • If the contact is the last element, just decrease the count.
  • If the contact is not last element, copy the last contact to its position and then decrease the count.


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.

Execution

Combining each of these elements, we get the executable source code:

On executing this code, we get the following output:

Comment
Article Tags: