All writing

C Programming: Learn the Basics in 5 Days

Five days through the fundamentals of C: variables, input and output, every loop form, functions, and a mini project to tie it together.

Dive into the fundamentals of C programming with this comprehensive 5-day tutorial. Ideal for beginners, this guide covers loops, conditionals, basic input/output operations, and more to kickstart your journey into programming.


Jump to Section

C Programming Tutorial

Welcome to your C programming tutorial! Over the next five days, you’ll embark on a journey to learn the foundational elements of C, one of the most powerful and widely-used programming languages. By the end of this tutorial, you will have a solid understanding of key programming concepts that will serve as a stepping stone to more advanced topics.


Hello World with Variables Declaration

This program declares variables, takes input, and displays output, reinforcing your understanding of the core concepts.


#include <stdio.h>

int main() {
    int age = 20;
    char name[] = "Imad";
    printf("Hello %s, your age is %i years!\n", name, age);
    return 0;
}

Multiplication and Basic Input/Output

we’ll put together what you’ve learned and introduce basic input/output operations. You’ll write a program that takes user input, performs some calculations, and displays the results. This will help you understand how to interact with users and handle data dynamically.


#include <stdio.h>

int main() {
    const int A = 10;
    const int B = 3;

    printf("%i * %i = %i\n", A, B, A * B);

    int x, y;
    char name[100];
    printf("Insert your name: ");
    scanf("%99s", name);
    printf("Enter two integers separated by a space: ");
    scanf("%d %d", &x, &y);
    printf("Hello: %s\n", name);
    printf("%d * %d = %d\n", x, y, x * y);
    return 0;
}


Loop Statements

while Statement

The while statement is the simplest loop construct. It looks like this:

while (test)
  body

Here, body is a statement (often a nested block) to repeat, and test is the test expression that controls whether to repeat it again. Each iteration of the loop starts by computing test and, if it is true (nonzero), that means the loop should execute body again and then start over.

Here’s an example of advancing to the last structure in a chain of structures chained through the next field:

#include <stddef.h> /* Defines NULL. */

while (chain->next != NULL)
  chain = chain->next;

This code assumes the chain isn’t empty to start with; if the chain is empty (that is, if chain is a null pointer), the code gets a SIGSEGV signal trying to dereference that null pointer


do-while Statement

The dowhile statement is a simple loop construct that performs the test at the end of the iteration.

do
  body
while (test);

Here, body is a statement (possibly a block) to repeat, and test is an expression that controls whether to repeat it again.

Each iteration of the loop starts by executing body. Then it computes test and, if it is true (nonzero), that means to go back and start over with body. If test is false (zero), then the loop stops repeating and execution moves on past it.

break Statement


The break statement looks like ‘break;’. Its effect is to exit immediately from the innermost loop construct or switch statement .

For example, this loop advances p until the next null character or newline.

while (*p)
  {
    /* End loop if we have reached a newline.  */
    if (*p == '\n')
      break;
    p++
  }

When there are nested loops, the break statement exits from the innermost loop containing it.

struct list_if_tuples
{
  struct list_if_tuples next;
  int length;
  data *contents;
};

void
process_all_elements (struct list_if_tuples *list)
{
  while (list)
    {
      /* Process all the elements in this node’s vector,
         stopping when we reach one that is null.  */
      for (i = 0; i < list->length; i++
        {
          /* Null element terminates this node’s vector.  */
          if (list->contents[i] == NULL)
            /* Exit the for loop.  */
            break;
          /* Operate on the next element.  */
          process_element (list->contents[i]);
        }

      list = list->next;
    }
}

for Statement

A for statement uses three expressions written inside a parenthetical group to define the repetition of the loop. The first expression says how to prepare to start the loop. The second says how to test, before each iteration, whether to continue looping. The third says how to advance, at the end of an iteration, for the next iteration. All together, it looks like this:

for (start; continue-test; advance)
  body

The first thing the for statement does is compute start. The next thing it does is compute the expression continue-test. If that expression is false (zero), the for statement finishes immediately, so body is executed zero times.

However, if continue-test is true (nonzero), the for statement executes body, then advance. Then it loops back to the not-quite-top to test continue-test again. But it does not compute start again.


Example of for

Here is the for statement from the iterative Fibonacci function:

int i;
for (i = 1; i < n; ++i)
  /* If n is 1 or less, the loop runs zero times,  */
  /* since i < n is false the first time.  */
  {
    /* Now last is fib (i)
       and prev is fib (i - 1).  */
    /* Compute fib (i + 1).  */
    int next = prev + last;
    /* Shift the values down.  */
    prev = last;
    last = next;
    /* Now last is fib (i + 1)
       and prev is fib (i).
       But that won’t stay true for long,
       because we are about to increment i.  */
  }

In this example, start is i = 1, meaning set i to 1. continue-test is i < n, meaning keep repeating the loop as long as i is less than n. advance is i++, meaning increment i by 1. The body is a block that contains a declaration and two statements.


For Index Declarations

You can declare loop-index variables directly in the start portion of the for-loop, like this:

for (int i = 0; i < n; ++i)
  {
    
  }

This kind of start is limited to a single declaration; it can declare one or more variables, separated by commas, all of which are the same basetype (int, in this example):

for (int i = 0, j = 1, *p = NULL; i < n; ++i, ++j, ++p)
  {
    
  }

The scope of these variables is the for statement as a whole. basetype.

Variables declared in for statements should have initializers. Omitting the initialization gives the variables unpredictable initial values, so this code is erroneous.

for (int i; i < n; ++i)
  {
    
  }

Functions

Function Definitions

We have already presented many examples of function definitions. To summarize the rules, a function definition looks like this:

returntype
functionname (parm_declarations)
{
  body
}

The part before the open-brace is called the function header.

Write void as the returntype if the function does not return a value.


Function Declarations

To call a function, or use its name as a pointer, a function declaration for the function name must be in effect at that point in the code. The function’s definition serves as a declaration of that function for the rest of the containing scope, but to use the function in code before the definition, or from another compilation module, a separate function declaration must precede the use.

A function declaration looks like the start of a function definition. It begins with the return value type (void if none) and the function name, followed by argument declarations in parentheses (though these can sometimes be omitted). But that’s as far as the similarity goes: instead of the function body, the declaration uses a semicolon.

A declaration that specifies argument types is called a function prototype. You can include the argument names or omit them. The names, if included in the declaration, have no effect, but they may serve as documentation.

This form of prototype specifies fixed argument types:

rettype function (argtypes);

This form says the function takes no arguments:

rettype function (void);

This form declares types for some arguments, and allows additional arguments whose types are not specified:

rettype function (argtypes, ...);

For a parameter that’s an array of variable length, you can write its declaration with ‘*’ where the “length” of the array would normally go; for example, these are all equivalent.

double maximum (int n, int m, double a[n][m]);
double maximum (int n, int m, double a[*][*]);
double maximum (int n, int m, double a[ ][*]);
double maximum (int n, int m, double a[ ][m]);

The old-fashioned form of declaration, which is not a prototype, says nothing about the types of arguments or how many they should be:

rettype function ();

Warning: Arguments passed to a function declared without a prototype are converted with the default argument promotions . Likewise for additional arguments whose types are unspecified.

Function declarations are usually written at the top level in a source file, but you can also put them inside code blocks. Then the function name is visible for the rest of the containing scope. For example:

void
foo (char *file_name)
{
  void save_file (char *);
  save_file (file_name);
}

If another part of the code tries to call the function save_file, this declaration won’t be in effect there. So the function will get an implicit declaration of the form extern int save_file ();. That conflicts with the explicit declaration here, and the discrepancy generates a warning.

The syntax of C traditionally allows omitting the data type in a function declaration if it specifies a storage class or a qualifier. Then the type defaults to int. For example:

static foo (double x);

defaults the return type to int. This is bad practice; if you see it, fix it.

Calling a function that is undeclared has the effect of an creating implicit declaration in the innermost containing scope, equivalent to this:

extern int function ();

This declaration says that the function returns int but leaves its argument types unspecified. If that does not accurately fit the function, then the program needs an explicit declaration of the function with argument types in order to call it correctly.

Implicit declarations are deprecated, and a function call that creates one causes a warning.


Function Calls

Starting a program automatically calls the function named main . Aside from that, a function does nothing except when it is called. That occurs during the execution of a function-call expression specifying that function.

A function-call expression looks like this:

function (arguments)

Most of the time, function is a function name. However, it can also be an expression with a function pointer value; that way, the program can determine at run time which function to call.

The arguments are a series of expressions separated by commas. Each expression specifies one argument to pass to the function.

The list of arguments in a function call looks just like use of the comma operator, but the fact that it fills the parentheses of a function call gives it a different meaning.

Here’s an example of a function call, taken from an example near the

printf ("Fibonacci series item %d is %d\n",
        19, fib (19));

The three arguments given to printf are a constant string, the integer 19, and the integer returned by fib (19).


Function Call Semantics

The meaning of a function call is to compute the specified argument expressions, convert their values according to the function’s declaration, then run the function giving it copies of the converted values. (This method of argument passing is known as call-by-value.) When the function finishes, the value it returns becomes the value of the function-call expression.

Call-by-value implies that an assignment to the function argument variable has no direct effect on the caller. For instance,

#include <stdlib.h>  /* Defines EXIT_SUCCESS. */
#include <stdio.h>   /* Declares printf. */

void
subroutine (int x)
{
  x = 5;
}

void
main (void)
{
  int y = 20;
  subroutine (y);
  printf ("y is %d\n", y);
  return EXIT_SUCCESS;
}

prints ‘y is 20’. Calling subroutine initializes x from the value of y, but this does not establish any other relationship between the two variables. Thus, the assignment to x, inside subroutine, changes only that x.

If an argument’s type is specified by the function’s declaration, the function call converts the argument expression to that type if possible. If the conversion is impossible, that is an error.

Mini Project

Bank Employee Management Project




#include <stdio.h>
#include <stdlib.h>

struct employee
{
    int emp_id;
    char name[30];
    char dep[10];
    char gender;
    char phone_num[15];
    char dob[15];
    char join_date[10];
    int age;
    float salary;
    char address[500];
};

typedef struct employee Emp;

void Insert();
void Display();
void Search();
void Update();
void Delete();
void main_menu();
void login();
void end();

int main()
{
    login();
    main_menu();
}

void login()
{
    int a = 0, i = 0;
    char uname[10], c = ' ';
    char pword[10], code[10];
    char user[10] = "user";
    char pass[10] = "pass";
    do
    {
        printf("\n__________________________________________________________________________________________________________\n");
        printf("\n ::::::::::::::::::::::::::::::::::::::::::::::::  LOGIN  :::::::::::::::::::::::::::::::::::::::::::::::\n");
        printf(" \n                                            ENTER USERNAME : ");
        scanf("%s", &uname);
        printf(" \n                                            ENTER PASSWORD : ");
        while (i < 10)
        {
            pword[i] = getch();
            c = pword[i];
            if (c == 13)
                break;
            else
                printf("*");
            i++;
        }
        pword[i] = '\0';
        i = 0;

        if (strcmp(uname, "user") == 0 && strcmp(pword, "pass") == 0)
        {
            printf("\n__________________________________________________________________________________________________________\n");
            printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  WELCOME TO TRIDENT BANK EMPLOYEE MANAGEMENT SYSTEM  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            printf("\n__________________________________________________________________________________________________________\n");
            printf("\n\nC-Language Project\nGroup Members: \n\n1.Lalit Chaudhary (AP21110010424)\n2.Bhavana Sree Vemuri (AP21110010425)\n3.Venkata Krishna Saadhvik Muddana (AP2111001042)\n");
            printf("\n LOADING PLEASE WAIT... \n");
            for (i = 0; i < 5; i++)
            {
                printf(".");
                Sleep(500);
            }
            printf("\n\n\n                                       Press any key to continue...\n\n");
            getch();
            break;
        }
        else
        {
            printf("\nSORRY !!!!  LOGIN IS UNSUCESSFUL");
            printf("\nIncorrect Credentials !!!\n");
            a++;
        }
    } while (a <= 3);
    if (a > 3)
    {
        printf("\nSorry you have entered the wrong username and password 4 times !!!\n");
        printf("Your Session has been terminated due to attempted incorrect logins !!!\n");
        end();
    }
}

void main_menu()
{

    int ch;
    do
    {
        printf("\n\n\n");
        printf("~~~~~~  Main Menu  ~~~~~~\n\n");
        printf("\n1. Add New Employee Record\n\n2. Display All Records\n\n3. Search Specific Employee Record\n\n4. Update Employee Record\n\n5. Delete Employee Record\n\n6. Exit The Program \n\n\nEnter your Choice : ");
        scanf("%d", &ch);
        printf("\n\n\n");

        switch (ch)
        {
        case 1:
            Insert();
            break;
        case 2:
            Display();
            break;
        case 3:
            Search();
            break;
        case 4:
            Update();
            break;
        case 5:
            Delete();
            break;
        case 6:
            end();
        default:
            printf("\nIncorrect Choice !!!\nTry Again...!\n");
        }
    } while (ch != 6);
}

void Insert()
{
    FILE *fp;
    fp = fopen("emp.txt", "a+");
    if (fp == NULL)
    {
        printf("\nUnable to access file........Try Again....!!");
    }
    else
    {
        printf("\n_______________________________________________\n");
        printf("\n~~~~~~~~~~~ INSERT EMPLOYEE RECORDS ~~~~~~~~~~~\n");
        printf("\n_______________________________________________\n");
        int n, a;
        printf("\nEnter the number of Records you want to insert : ");
        scanf("%d", &n);
        Emp *e;
        e = (Emp *)calloc(n, sizeof(Emp));

        for (int i = 0; i < n; i++)
        {
            printf("\n\n~~~~~~~~~~~~~~~~~~ EMPLOYEE - %d ~~~~~~~~~~~~~~~~~~\n", i + 1);

            printf("\nEnter Employee ID : ");
            scanf("%d", &e[i].emp_id);

            printf("\nEnter Full Name of Employee : ");
            scanf("\n");
            scanf("%[^\n]s", &e[i].name);

            printf("\nEnter Department of Employee : ");
            scanf("\n");
            scanf("%[^\n]s", &e[i].dep);

            printf("\nEnter Employee Age : ");
            scanf("%d", &a);
            if (a < 18)
            {
                printf("\n\nUnder Age for job !!!\nGive Age above 18\n");
                printf("\nEnter Employee Age : ");
                scanf("%d", &e[i].age);
            }

            else if (a > 60)
            {
                printf("\n\nOver Aged for job !!!\nGive age below 60\n");
                printf("\nEnter Employee Age : ");
                scanf("%d", &e[i].age);
            }

            else
            {
                e[i].age = a;
            }

            printf("\nEnter Employee Salary : ");
            scanf("%f", &e[i].salary);

            printf("\nEnter Employee Gender : ");
            scanf("%s", &e[i].gender);

            printf("\nEnter Employee Phone Number : ");
            scanf("%s", &e[i].phone_num);

            printf("\nEnter Employee DOB : ");
            scanf("\n");
            gets(e[i].dob);

            printf("\nEnter Employee joining date : ");
            scanf("\n");
            gets(e[i].join_date);

            printf("\nEnter Employee Address : ");
            scanf("\n");
            scanf("%[^\n]s", &e[i].address);

            fwrite(e + i, sizeof(Emp), 1, fp);
        }
        printf("\n~~~~~~~~~~~ RECORD INSERTED SUCCESFULLY ~~~~~~~~~~~\n");
    }
    fclose(fp);
}

void Display()
{
    FILE *fp;
    fp = fopen("emp.txt", "r");
    Emp e;
    if (fp == NULL)
    {
        printf("\nUnable to access file ........Try Again........ !!");
    }

    else
    {
        printf("\n_______________________________________________________\n");
        printf("\n~~~~~~~~~~~ DISPLAY ALL EMPLOYEE RECORD ~~~~~~~~~~~\n");
        printf("\n_______________________________________________________\n\n");
        printf("\n\n_______________________________________________________________________________________________________________________________________________________________________________________________");
        char *h[] = {"ID", "NAME", "GENDER", "DOB", "DEPARTMENT", "JOIN DATE", "AGE", "SALARY", "PHONE NUMBER", "ADDRESS"};
        printf("\n\n\t%-5s %-30s %-8s %-15s %-20s %-10s %-8s %-25s %-20s %-30s\n", h[0], h[1], h[2], h[3], h[4], h[5], h[6], h[7], h[8], h[9]);
        printf("_______________________________________________________________________________________________________________________________________________________________________________________________\n\n");
        while (fread(&e, sizeof(Emp), 1, fp))
        {
            /*printf("\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                printf("\n\n\n\tID \t: %d \n\n",e.emp_id);
                printf("\tNAME \t: %s \n\n",e.name);
                printf("\tGENDER \t: %c \n\n",e.gender);
                printf("\tDOB \t: %s \n\n",e.dob);
                printf("\tPHONE NUMBER \t: %d \n\n",e.phone_num);
                printf("\tAGE \t: %d \n\n",e.age);
                printf("\tJOIN DATE \t: %s \n\n",e.join_date);
                printf("\tDEPARTMENT \t: %s \n\n",e.dep);
                printf("\tSALARY \t: %0.2f \n\n",e.salary);
                printf("\tADDRESS \t: %s \n\n\n\n",e.address);
                printf("\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");*/
            printf("\n\t%-5d %-30s %-8c %-15s %-20s %-10s %-8d %-25.2f %-20s %-30s\n", e.emp_id, e.name, e.gender, e.dob, e.dep, e.join_date, e.age, e.salary, e.phone_num, e.address);
        }
    }
    fclose(fp);
}

void Search()
{
    FILE *fp;
    fp = fopen("emp.txt", "r");
    if (fp == NULL)
    {
        printf("\nUnable to access file ........Try Again........ !!");
    }
    else
    {
        printf("\n_______________________________________________________\n");
        printf("\n~~~~~~~~~~~ DISPLAY SEPECIFIC EMPLOYEE RECORD ~~~~~~~~~~~\n");
        printf("\n_______________________________________________________\n\n");
        Emp e;
        printf("\nEnter the Employee ID you want to search : ");
        int ID, found = 0;
        scanf("%d", &ID);

        while (fread(&e, sizeof(Emp), 1, fp))
        {
            if (e.emp_id == ID)
            {
                printf("\nEmployee Record is Found !!!!!!!!\n");
                printf("\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                printf("\n\n\n\tID \t: %d \n\n", e.emp_id);
                printf("\tNAME \t: %s \n\n", e.name);
                printf("\tGENDER \t: %c \n\n", e.gender);
                printf("\tDOB \t: %s \n\n", e.dob);
                printf("\tPHONE NUMBER \t: %s \n\n", e.phone_num);
                printf("\tAGE \t: %d \n\n", e.age);
                printf("\tJOIN DATE \t: %s \n\n", e.join_date);
                printf("\tDEPARTMENT \t: %s \n\n", e.dep);
                printf("\tSALARY \t: %0.2f \n\n", e.salary);
                printf("\tADDRESS \t: %s \n\n\n\n", e.address);
                printf("\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                found = 1;
                break;
            }
        }
        if (found == 0)
        {
            printf("\nEmployee Record not found ........Try Again........ !!");
        }
    }
    fclose(fp);
}

void Update()
{
    FILE *fp, *fp1;

    if (fp == NULL)
    {
        printf("\nUnable to access file ........Try Again........ !!");
    }
    else
    {
        printf("\n_______________________________________________________\n");
        printf("\n~~~~~~~~~~~ UPDATE EMPLOYEE RECORD ~~~~~~~~~~~\n");
        printf("\n_______________________________________________________\n\n");
        fp = fopen("emp.txt", "r");
        fp1 = fopen("temp.txt", "w");
        Emp e;
        int ch;
        printf("\nEnter the Employee ID you want to Update : ");
        int ID, found = 0;
        scanf("%d", &ID);

        while (fread(&e, sizeof(Emp), 1, fp))
        {
            if (e.emp_id == ID)
            {
                printf("\n\nCurrent Details Available for this Employee ID -  %d : \n", ID);
                printf("\n\nEmployee Record is Found !!!!!!!!\n\n\n");
                printf("\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                printf("\n\n\n\tID \t: %d \n\n", e.emp_id);
                printf("\tNAME \t: %s \n\n", e.name);
                printf("\tGENDER \t: %c \n\n", e.gender);
                printf("\tDOB \t: %s \n\n", e.dob);
                printf("\tPHONE NUMBER \t: %d \n\n", e.phone_num);
                printf("\tAGE \t: %d \n\n", e.age);
                printf("\tJOIN DATE \t: %s \n\n", e.join_date);
                printf("\tDEPARTMENT \t: %s \n\n", e.dep);
                printf("\tSALARY \t: %0.2f \n\n", e.salary);
                printf("\tADDRESS \t: %s \n\n\n\n", e.address);
                printf("\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                found = 1;

                do
                {
                    printf("\n________________________________\n\n\n");
                    printf("\nWhat would you like to update : \n\n\n1. Name\n\n2. Department\n\n3. Age\n\n4. Salary\n\n5. Phone Number\n\n6. Address\n\n7.All Information !\n\n8.Exit\n\n\nEnter Your Choice : ");
                    scanf("%d", &ch);
                    printf("\n\n");
                    switch (ch)
                    {
                    case 1:
                        printf("\nEnter Full Name of Employee : ");
                        scanf("\n");
                        gets(e.name);
                        break;

                    case 2:
                        printf("\nEnter Department of Employee : ");
                        scanf("\n");
                        scanf("%s", &e.dep);
                        break;

                    case 3:
                        printf("\nEnter Employee Age : ");
                        scanf("%d", &e.age);
                        break;

                    case 4:
                        printf("\nEnter Employee Salary : ");
                        scanf("%f", &e.salary);
                        break;

                    case 5:
                        printf("\nEnter Employee Phone Number : ");
                        scanf("%s", &e.phone_num);
                        break;

                    case 6:
                        printf("\nEnter Employee Address : ");
                        scanf("\n");
                        gets(&e.address);
                        break;

                    case 7:
                        printf("\nEnter Employee ID : ");
                        scanf("%d", &e.emp_id);
                        printf("\nEnter Full Name of Employee : ");
                        scanf("\n");
                        gets(e.name);
                        printf("\nEnter Department of Employee : ");
                        scanf("\n");
                        scanf("%s", &e.dep);
                        printf("\nEnter Employee Age : ");
                        scanf("%d", &e.age);
                        printf("\nEnter Employee Salary : ");
                        scanf("%f", &e.salary);
                        printf("\nEnter Employee Gender : ");
                        scanf("%s", &e.gender);
                        printf("\nEnter Employee Phone Number : ");
                        scanf("%s", &e.phone_num);
                        printf("\nEnter Employee DOB : ");
                        scanf("\n");
                        gets(&e.dob);
                        printf("\nEnter Employee joining date : ");
                        gets(&e.join_date);
                        printf("\nEnter Employee Address : ");
                        gets(&e.address);
                        break;

                    case 8:
                        break;

                    default:
                        printf("\nIncorrect Choice............Try Again....!\n");
                        break;
                    }
                    if (ch != 8)
                    {
                        printf("\nWould You like to do some more updations with this record...{Y/N) : ");
                        char c;
                        scanf("\n");
                        scanf("%c", &c);
                        if (c == 'y' || c == 'Y')
                        {
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }

                } while (ch != 8);
            }
            fwrite(&e, sizeof(Emp), 1, fp1);
        }
        fclose(fp);
        fclose(fp1);

        if (found == 1)
        {
            fp = fopen("emp.txt", "w+");
            fp1 = fopen("temp.txt", "r+");
            while (fread(&e, sizeof(Emp), 1, fp1))
            {
                fwrite(&e, sizeof(Emp), 1, fp);
            }
            fclose(fp);
            fclose(fp1);
            if (ch != 8)
            {
                printf("\nRecord Updated Successfully..........!\n");
            }
        }
        else
        {
            printf("\nThe Eployee ID is not found........Try Again.........!\n");
        }
    }
}

void Delete()
{
    FILE *fp, *fp1;

    if (fp == NULL)
    {
        printf("\nUnable to access file........Try Again....!!");
    }
    else
    {
        printf("\n_______________________________________________________\n");
        printf("\n~~~~~~~~~~~ DELETE EMPLOYEE RECORD ~~~~~~~~~~~\n");
        printf("\n_______________________________________________________\n\n");
        fp = fopen("emp.txt", "r");
        fp1 = fopen("temp.txt", "w");
        Emp e;
        printf("\nEnter the Employee ID you want to Delete : ");
        int ID, found = 0;
        scanf("%d", &ID);

        while (fread(&e, sizeof(Emp), 1, fp))
        {
            if (e.emp_id == ID)
            {
                found = 1;
            }
            else
            {
                fwrite(&e, sizeof(Emp), 1, fp1);
            }
        }
        fclose(fp);
        fclose(fp1);

        if (found == 1)
        {
            fp = fopen("emp.txt", "w+");
            fp1 = fopen("temp.txt", "r+");
            while (fread(&e, sizeof(Emp), 1, fp1))
            {
                fwrite(&e, sizeof(Emp), 1, fp);
            }
            fclose(fp);
            fclose(fp1);
            printf("\nRecord Deleted Successfully..........!\n");
        }
        else
        {
            printf("\nThe Eployee ID is not found........Try Again.........!\n");
        }
    }
}

void end()
{
    printf("Thanks for using our program !!!\n");
    printf("Have a great day !!!\n");
    exit(10);
}