title: Deleting a contact from a phone book code in c
body: <p>Having trouble deleting a contact from my phone book code. The other functions work just fine, but when I go to delete a contact it just stops the program.</p>
  
  <p>I've tried looking up different examples, but haven't found anything that has worked for me yet.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  struct contact {                // Data structure that holds contact information 
      char FirstName[10];         // Array for first name
      char LastName[10];          // Array for last name
      int PhoneNum;               // Phone number
  };
  
  int main() {
  
      // Setting up variables
      int Function = 0;
      int Choice = 0;
      char FName[200][10];
      char LName[200][10];
      int PNum = 0;
      int n = 1;
      int size = 1;
      struct contact *con = (struct contact *)malloc(size * sizeof(struct contact));
      int b = 0, a = 0;
      int DelCon = 0;
  
      do {     // Will loop through the main function until the user decides to exit the program
  
          // Prints out the main menu of the phone book
          printf("\nPhone Book");
          printf("\n[1] Add a contact");
          printf("\n[2] Delete a contact");
          printf("\n[3] Show contacts");
          printf("\n[4] Exit program");
          printf("\n\nWhat function would you like to use?\n");       // Asks for user input
          scanf("%d", &amp;Choice);
  
          switch (Choice) {
          case 1:     // Case to add a contact into the phone book
              printf("\nYou chose to add a contact.");
              printf("\nFirst name: ");
              scanf("%s", &amp;FName[b]);
              printf("\nLast name: ");
              scanf("%s", &amp;LName[b]);
              printf("\nPhone number (Numbers only): ");
              scanf("%d", &amp;PNum);
              printf("\nRecord added to the phone book");
  
              // Records the information given into the structure
              if (n &gt;= size)
              {
                  size = size * 2;
                  con = (struct contact*)realloc(con, size * sizeof(struct contact));
              }
              a = (n - 1);
  
              strcpy(con[a].FirstName, FName[b]);
              strcpy(con[a].LastName, LName[b]);
              con[a].PhoneNum = PNum;
  
              b = (b + 1);
              n++;
  
              // Prints out the given information
              printf("\n\nNew contact:");
              printf("\nFirst name: %s", con[a].FirstName);
              printf("\nLast name: %s", con[a].LastName);
              printf("\nPhone number: %d", con[a].PhoneNum);
              printf("\nContact number is %d", a);
              printf("\n");
              break;
          case 2:     // Case to delete a contact from the phone book
              printf("\nYou chose to delete a contact.");
              printf("\nWhich contact would you like to delete? Specify by contact number. ");
              scanf("%d", &amp;DelCon);
              a = DelCon;
              char DelF = 0;
              char DelL = 0;
              int DelNum = 0;
              strcpy(con[a].FirstName, DelF);
              strcpy(con[a].LastName, DelL);
              strcpy(con[a].PhoneNum, DelNum);
              printf("\nContact deleted");
              printf("\n");
              break;
          case 3:     // Case to see all of the entered contacts
              printf("\nYou chose to show the contacts.");
              for (a = 0; a &lt; (n - 1); a++) {
                  printf("\nContact #%d", a);
                  printf("\nFirst name: %s", con[a].FirstName);
                  printf("\nLast name: %s", con[a].LastName);
                  printf("\nPhone number: %d", con[a].PhoneNum);
                  printf("\n");
              }
              break;
          case 4:
              printf("Goodbye!");
              break;
          }
      } while (Choice != 4);
      return 0;
  }
  </code></pre>
  
  <p>Here is what my code printed out.</p>
  
  <pre><code>Phone Book
  [1] Add a contact
  [2] Delete a contact
  [3] Show contacts
  [4] Exit program
  
  What function would you like to use?
  1
  
  You chose to add a contact.
  First name: test
  
  Last name: 1
  
  Phone number (Numbers only): 1234567
  
  Record added to the phone book
  
  New contact:
  First name: test
  Last name: 1
  Phone number: 1234567
  Contact number is 0
  
  Phone Book
  [1] Add a contact
  [2] Delete a contact
  [3] Show contacts
  [4] Exit program
  
  What function would you like to use?
  1
  
  You chose to add a contact.
  First name: Test
  
  Last name: 2
  
  Phone number (Numbers only): 8901234
  
  Record added to the phone book
  
  New contact:
  First name: Test
  Last name: 2
  Phone number: 8901234
  Contact number is 1
  
  Phone Book
  [1] Add a contact
  [2] Delete a contact
  [3] Show contacts
  [4] Exit program
  
  What function would you like to use?
  3
  
  You chose to show the contacts.
  Contact #0
  First name: test
  Last name: 1
  Phone number: 1234567
  
  Contact #1
  First name: Test
  Last name: 2
  Phone number: 8901234
  
  Phone Book
  [1] Add a contact
  [2] Delete a contact
  [3] Show contacts
  [4] Exit program
  
  What function would you like to use?
  2
  
  You chose to delete a contact.
  Which contact would you like to delete? Specify by contact number. 0
  
  --------------------------------
  Process exited with return value 3221225477
  </code></pre>
  
  <p>It should be deleting the contact and returning back to the menu.</p>