Friday, November 3, 2023

Chapter 2: Contact Management in C | File Handling

 <<Previous Chapter

If you remember we have categoried all the functions into two types user functions and operational functions. Here I will explain the operational function and its usage in user functions one by one.

First, let's define Variables and Data Structure.


// Define Constant Variables
#define ESC 27
#define MAX_NAME_SZ 15
#define MAX_NUM_SZ 25
#define READ_ARRAY_SZ 15
#define DATA_FILE "dataFile.dat"
#define TEMP_FILE "tempFile.dat"

//Define data structure

struct data{
    char fName[MAX_NAME_SZ];
    char lName[MAX_NAME_SZ];
    char mPhone[MAX_NUM_SZ];
    char wPhone[MAX_NUM_SZ];
    char hPhone[MAX_NUM_SZ];
};
We will use struct data types to store contact information. It has only five fields First Name (fName), Last Name (lName), Mobile Phone (mPhone), Work Phone (wPhone), Home Phone (hPhone), and all these variables are char types. We can't set primary key as in database but we will choose Mobile Phone i.e mPhone as a primary key and will make sure that Mobile Phone number will not be a null value or duplicate while adding data into the file.

Wednesday, November 1, 2023

Chapter 1: Contact Management in C | Flow Chart and Functions

<<Previous Chapter                                                                                                            Next Chapter>> 

Application Flow Chart:




Functions: 
We will divide the above application into two kinds of functions. The first type of function is user functions which interact with the user to get input and display output, the second type of function is operational functions which do the actual tasks. 

The list of user functions is as follows:
  • mainMenu(): It displays the options to the user. 
  • viewItems(): It displays the list of contact information on the screen. 
  • addItems(): It requests the user to input contact information added to the file.
  • updateItems(): It requests the user to update the contact information in the file.
  • deleteItems(): It requests the user to delete the contact information in the file.
  • readData(): It requests the user to input contact information.