title: malloc and free with a dynamically changing structure
body: <p>I am having trouble with moving my pointer in a dynamically changing structure. 
  I have created my code where you can malloc more memory and this seems to be working.
  The problems that I am running into is how to add to the structure, how to free memory and how to move from structure to structure and print all items. </p>
  
  <p>I am trying to test add and print (the delete function that is there does not seem to work, segfaults)</p>
  
  <p>When I add to the struct and then print the struct I get a segfault from the values that I have added. I don't know if I am moving from the first struct to the next struct correctly.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include "pointer.h"
  
  /********************************************
  Creates more memory for size (strut * rec+1)
  *********************************************/
  
  employee *create(int record){
  employee *new_employee = malloc(sizeof(employee) * (record+1));
  
  return new_employee;    
  }
  
  /********************************************
  Copies the data from one structure to a new structure with 
  size "structure" multipled by rec+1
  ***********************************************/
  employee *copy(employee *data, int record){
      employee *new_employee = create(record);
  int i;
      for(i = 0; i&lt;record;i++){
          new_employee-&gt;first = data-&gt;first;
          new_employee-&gt;last = data-&gt;last;
          new_employee-&gt;start_date = data-&gt;start_date;
          new_employee-&gt;sal = data-&gt;sal;
          data++;
      }
      /********************
      Needs to free the old struct
      *********************/
      //deleteData(data, record);
  
  return new_employee;
  }
  /********************************************
  Function prints everything in the struct
  *********************************************/
  void printStruct(employee *data, int record){
  int i;
  
      for(i = 0; i&lt;record; i++){
          printf("\nEntry: %d\n", i+1);           
          printf("The employee's name is %s %s\n", data-&gt;first, data-&gt;last);
          printf("The employee was hired on: %s\n", data-&gt;start_date);
          printf("The employee make $%f\n\n", data-&gt;sal); 
          data++;     
      }
  }
  /******************************************
  Function frees the old data base
  *******************************************/
  void deleteData(employee *data, int record){
  int i;
      for(i = 0; i&lt;record; i++){
          free(data-&gt;first);
          free(data-&gt;last);
          free(data-&gt;start_date);
          data++;
      }
      free(data);
  }
  /******************************************
  Adds an employee to the new structure
  *******************************************/
  employee *add(employee *data,char *fname, char *lname, char *date, float salary, int record){
  employee *employeeDB = create(record);
  employeeDB = copy(data, record);
  int i;
      employeeDB++;
      employeeDB-&gt;first = fname;
      employeeDB-&gt;last = lname;
      employeeDB-&gt;start_date = date;
      employeeDB-&gt;sal = salary;
  
  return employeeDB;
  }
  
  
  
  
  /**************************
  Starts of the main function
  ***************************/
  
  int main(void){
      //Keeps track of the number of records that are in the structure
  int rec = 0;
      //Keeps the number of accesses to the structure. Even with the one entry   the structure has not been accessed. 
  int acc = 0;
      //Holds the input information for the menu
  int input;
      //holds the information for inputing user first name
  char *fname;
      //holds the information for inputing user last name
  char *lname;
      //holds the information for for the startdate
  char *start;
      //holds the information for the salary;
  float sal;
  /*********************************
  This next section adds an employee to the record
  
  ************************************/
  //This creates the first entry to the dynamic structure.
  employee *first_employee = create(rec);
  first_employee-&gt;first = "FIRST";
  first_employee-&gt;last = "LAST";
  first_employee-&gt;start_date = "June-20th-2006";
  first_employee-&gt;sal = 55555.55;
  //increase the number of records    
  rec = rec+1;
  
  employee *new_employeeDB = add(first_employee, "fname", "lname", "JUNE-20th-2010", 55555.55, rec);
  rec = rec + 1;
  printStruct(new_employeeDB, rec);
  
  
  printf("%d\n", (sizeof(employee)* rec));
  
  
  }
  </code></pre>