how to delete a pointer in c++ : <p>I have been editing and compiling my program for two weeks now, but it keeps on stopped working whenever I try to delete a pointer. Please help me identify the problem when deleting a pointer that contains the employee ID entered. I am new to c++ and this makes me crazy.</p>

<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;

using namespace std;

struct nameType
{
    string first, middle, last;

};

struct addressType
{
    string add1, add2, city, state;
    int zip;
};

struct dateType
{
    int month, day, year;

};

struct contactType
{
    int phone, cellphone, fax, pager;
    string email;
};

struct employeeType
{
    nameType name;
    string empID;
    addressType address;
    dateType hireDate;
    dateType quitDate;
    contactType contact;
    string deptID;
    double salary;

    struct employeeType *pnext, *prev;
};

employeeType *pc, *del, *head;

char choice;


void AddEmp()
{
    pc = new employeeType;
    del -&gt; pnext = pc;
    pc -&gt; prev = del;
    del = pc;
    pc -&gt; pnext = NULL;



    cout &lt;&lt; "\t\n\nNAME "&lt;&lt;endl;    
    cout&lt;&lt; "First: ";
    cin &gt;&gt; pc -&gt; name.first;
    cout&lt;&lt; "Middle: ";
    cin &gt;&gt; pc -&gt; name.middle;
    cout &lt;&lt; "Last: ";
    cin &gt;&gt; pc -&gt; name.last;

    cout &lt;&lt;"\nEmployee ID: ";
    cin &gt;&gt; pc -&gt; empID;



    cout&lt;&lt;"\t\nEnter choice: [A] ADD, [D] DISPLAY, [X] DELETE, [E], EXIT: ";
    cin &gt;&gt; choice;  
    system ("cls");     

}

void dispEntry()
{
    pc = head -&gt; pnext;

    do
    {

        cout &lt;&lt;"\t\t\t\t\t\n\nEMPLOYEE'S CONTACT DETAILS"&lt;&lt;endl&lt;&lt;endl;
        cout &lt;&lt;"["&lt;&lt;pc&lt;&lt;"]";

        cout &lt;&lt;"\t\t\t\nNAME"&lt;&lt;endl;
        cout &lt;&lt; "\nName: " &lt;&lt; pc -&gt; name.first &lt;&lt; "\nMiddle: "  &lt;&lt; pc -&gt; 
       name.middle &lt;&lt; "\nLast: "&lt;&lt; pc -&gt; name.last&lt;&lt; endl&lt;&lt;endl;

        cout &lt;&lt; "Employee ID: "&lt;&lt;pc -&gt; empID&lt;&lt;endl;


        pc = pc -&gt;pnext;                


    }while (pc !=NULL);

    cout&lt;&lt;"\t\nEnter choice: [A] ADD, [D] DISPLAY, [X] DELETE, [E], EXIT: ";
    cin &gt;&gt; choice;  
}
</code></pre>

<p>HERE is the code to delete a pointer, but it is not working.</p>

<pre><code>void delEntry ()
{

    string dataDel;
    system ("cls"); 
    cout &lt;&lt;" DELETE DATA"&lt;&lt; endl;
    cout&lt;&lt;"Enter Employee ID:";
    cin &gt;&gt; dataDel;



    while (dataDel != pc -&gt; empID )
    {
        pc = pc -&gt; pnext;       

    }

    del = pc;

    if(pc -&gt; pnext = NULL)
    {
        pc = del -&gt; prev;   
        pc -&gt;pnext = NULL;      

        delete del;
        del = pc;


    }
    else 
    {
        pc = del -&gt; prev;   
        pc -&gt; pnext = del -&gt; pnext;  
        del -&gt; pnext -&gt; prev = pc;


        delete del;
        del = pc;



    }

}


int main()
{
    char entryChoice;   
    pc = new employeeType;
    head = pc;
    del = pc;
    pc -&gt; prev = pc -&gt; pnext = NULL;




    cout &lt;&lt; "\t\t\t\t\nTHIS IS A PROGRAM TO ENTER EMPLOYEE'S CONTACT 
    DETAILS."&lt;&lt;endl&lt;&lt;endl;


    cout &lt;&lt; "\t\t\t\t\nEnter choice: [A] ADD, [D] DISPLAY, [X] DELETE, [E], 
    EXIT  "&lt;&lt;endl&lt;&lt;endl;
    cout &lt;&lt; "\t\t\tEnter choice :";
    cin &gt;&gt; choice;
    system ("cls");


   while (choice == 'A', 'D', 'X', 'E')
   {

        switch(choice)
        {

            case 'A': 
                AddEmp();
                break;

            case 'D':
                dispEntry();
                break;

            case 'X':
                delEntry ();
                dispEntry();
                break;



        }
    }

}
</code></pre>
