A Phone Book Application Using C

Phone book Application using C is a simple application that incorporated most of the features of C. I had discussed each of the features of this application between the code, although most of the code has comments. The phone book application provides features like storing a room/phone number into a database, sorting and finding the room number/phone number, etc. This phone book application uses the graphic library for interaction with users. This application can store up to five hundred entries but is not limited to it, user can increase and decrease as per their need. Users can add, update, delete, search and modify the details of the contact. This application has also the features of delete recovery so that users can recover the details in case of accidentally deleted.

The software code is written and compiled using Borland Turbo C++.

Source Code of A Phone Book Application Using C

The feature main() display a console menu that has the following option:

Add entry
Delete entry
Find room number
Find phone number
List all entries
Display total entries in the database
Sort entries
Load database from file
Exit
Each of these menu options calls the appropriate function for performing its designated operation.

Add Entry Function:

Does not return any value it is used to add valid inputs(only) into the database and display the entry which was added. * A valid inputs are positive number only.

  1. Room no. input with less than or equal to 4 digits only.
  2. Phone no. input with less than or equal to 8 digits only.
  3. Input of Zero for room no. or phone no. inputs are invalid.

Delete Entry Function:

  1. Used to delete entries in the database.
  2. Return 0 if room no. & phone no. was found in the database.
  3. Return -1 if room no. & phone no. is not found in the database.
  4. Note: Auto-Recovery was implemented into this function but was never used.
  5. room_tmp array contains the deleted data which may be used for recovery.

FindPhone function:

  1. Used to search for a phone number in the database.
  2. Return 0 if the phone no. was found.
  3. Return -1 if the phone no. is not found.

The FindRroom and FindPhone function simply matches the input parameter to the function with the room and phone array and prints out the values if the match is found.

FindRoom function:

  1. Used to search for a Room number in the database.
  2. Return 0 if room no. was found.
  3. Return -1 if room no. is not found.

ListAll Function:

The ListAll function iterates through the room and phone array and displays the phone book entries to the user.

  1. Used for displaying data entered into the database.
  2. return -1 if the list is empty.
  3. return 0 if successful (database contains valid entries)

GeTotalEntries function: 
Used to return total entries added to the database.

SortAllEntries function:

The SortAllEntries uses the bubble sort method for sorting the phone book entries. The bubble sorting method used a temporary variable to swap the values. Sorting is done both in the ascending as well as in descending order. For the ascending order, each time the previous value is greater than the next value, the two values are swapped. For the ascending order, the same principle is used, only when the previous value is less than the next then the value is swapped. This entire process happens within a loop.

  1. Sort is done with the use of double sort.
  2. return 0 if the sort was successful.
  3. return -1 if the database is empty.

Chkstrdig(Check string for digits):

Used to check string inputs, and length
returning:

  1. -1 = if the string length is out of range.
  2. -2 = if a char is found within the string.
  3. 0 = if successful

NOTE: AddEntry specifies that the Room allows for 4 digits or less.
phone allowing 8 digits or less.

LoadDB Function:

The LoadDB function loads the phone book entries from a flat-file. The file is opened on line 647 using fopen and the data is loaded into the room and phone arrays (656 – 675).

Menu function:

These functions are used to draw the menu and the exit message on the screen. The ExitMenu function performs the task of saving the data to a flat-file before closing the application. The Menu function displays valid options on the screen.

ExitMenu function:
While exiting the system, asked the user if he/she wants to save the database into a file.

Drawscreen function: Draws program header.

Rfreshscreen function: used to refresh the color display.

 

Leave a Comment