title: Adding record to structure in C
body: <p>I've got structure of Books:</p>
  
  <pre><code> typedef struct {
     int ID;
     char* Title;
   } Book;
  </code></pre>
  
  <p>I just want to add record to Book table. That's my function:</p>
  
  <pre><code>void AddRecord(Book**b, int *records_num){
  
      *records_num = *records_num + 1;
  
      Book* temp = (Book*)malloc(sizeof(Book) * records_num);
  //FirstMethod
      memcpy(temp, *b, records_num * sizeof(Book)); //Doesn't work
  
      //SecondMethod
      int j;
  
      for(j = 0; j &lt; records_num - 1; j++){
          temp[j] = (*b)[j];
      }
  
      free(*b);
      *b = temp;
  //Some logic about adding a new record
  }
  </code></pre>
  
  <p>Both methods fails after run.
  That's how I call this function: <strong>AddRecord(books, &amp;number_of_lines);</strong>
  It doesn't work. What's wrong here?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I have changed some things in code. It still works bad, but gives no error.</p>
  
  <pre><code>void AddRecord(Book *b, int *records_num){
  
      *records_num = *records_num + 1;
  
      Book* temp = (Book *)malloc(sizeof(Book) * *records_num);
      memcpy(temp, b, sizeof(b));
      b = (Book *)realloc(b, sizeof(Book) * *records_num);
      memcpy(b, temp, sizeof(temp));
      b[*records_num - 1].ID = *records_num;
  }
  </code></pre>
  
  <p>Why this code is wrong?</p>