title: memcpy is not copying the data inside structs
body: <p>I am new c-programmer. I am developing a small student database. The database consists of structs student. Each student has a firstname, lastname and matriculation number. One method is to delete a student with a matriculation number. So i searched for matriculation number into the dynamic array. Then I tried to copy the elements that are before the element to remove and the elements that are after the element to remove into another dynamic array. The first problem is the copy-process. It does not work, although i using memcpy.When i have three elements and i delete one then i found 2 structs without informations. I means 2 empty structs in temp contains no Informations (like lastname......). I dont know why memcpy is not working.
  The second problem consists in the segmentation fault when i try to free my dynamic memory. What i am doing is after copying the new struct into temp. I free db. Then i set db=temp. So normally db is pointing to the new dynamic array. But I also get segmentation fault Here is code:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  typedef int bool;
  #define  true 1
  #define  false 0
  struct student{
      char lastname[20];
      char firstname[20];
      int  mNr;
     char courseOfStudy[20];
     char nationality[20];
  };
  
  struct student * db;
  struct student * ptrDb;
  int size=0;
  void createDb(int s){
      size=s;
      db= (struct student *)malloc(100*sizeof(struct student *));
      ptrDb=db;
      printf("database was created\n");
  }
  struct student getData(char lastname [], char firstname[], int matNr,   char courseOfStudy [], char nationality []){
      struct student st;
      memcpy(st.lastname,lastname,strlen(lastname));
      memcpy(st.firstname,firstname,strlen(firstname));
       st.mNr=matNr;
      memcpy(st.courseOfStudy,courseOfStudy, strlen(courseOfStudy));
      memcpy(st.nationality,nationality,strlen(nationality));
      printf("%s,%s,%d\n",st.lastname,st.firstname,st.mNr);
      return st;
   }
   //coping input by reference
   void insert_student(struct student *  st){
      *ptrDb=*st;
      ptrDb++;
  }
  
  bool delete_entry(int matNr){
      int new_size=size-1;
      int indexToRemove;
      int i;
      printf("look for the matriculation number: %d in the  Database:\n",matNr);
      for (i=0;i&lt;size;i++){
          if((db+i)-&gt;mNr==matNr){
              printf("student found\n");
              printf("new database size: %d:\n",new_size);
              indexToRemove=i+1;
              struct student * temp = (struct student *) malloc((new_size)*sizeof(struct student));
              memcpy(temp,db,indexToRemove-1);// copy all elements before indexToRemove
              memcpy(temp+indexToRemove,db+indexToRemove+1,size-indexToRemove+1);//copy all elements after indexRemoved
              int j=0;
              for(j=0;j&lt;new_size;j++){
                  puts("YES");
                   printf("lastname: %s, firstname:%s, enrollment nr:%d\n",(temp+j)-&gt;lastname,(temp+j)-&gt;firstname,(temp+j)-&gt;mNr);
          }
              free(db);//free the old dynamic memory
              db=temp;//now db is pointing to the new dynamic memory
              free(temp);//I dont need temp any more, free it
              return 1;
  
      }
  }   
  
  return 0;           
  </code></pre>
  
  <p>}</p>