title: C: Add and remove elements in an array of structs
body: <p>I have an array of structs, and each struct working as a list of elements.
  I need to add multiple objects to each struct and my add function it's not working properly.</p>
  
  <p>This is the Structure: </p>
  
  <pre><code>typedef struct object book, *list;
  struct object{
  int type;
  int quantity;
  list next;
  };
  </code></pre>
  
  <p>This is how I'm defining my array and what I have in the main() function:</p>
  
  <pre><code>row_n=4 //fixed just for now
  cols_n=3
  
  product **t;
  
  t= (product **)calloc(row_n, sizeof(product *));  // array of row pointers 
  for (int i= 0; i&lt;n; i++) {
  t[i]= (product *)calloc(cols_n, sizeof(product));  // array of cols prod structs 
  }
  
  t[1][1].type= 5; //only for testing
  t[1][1].quantity= 15; //only for testing
  list_all(t,row_n,col_n); //list all elements inside each array, its working as intended
  insert(t, 3, 6); //Trying to insert more books
  insert(t, 6, 10);
  insert(t, 9, 50);
  </code></pre>
  
  <p>This is the list_all function:</p>
  
  <pre><code>void list_all(product **t , int size_n , int size_m)
  {
  int i,j;
  product *p;
  
  for(i=0;i&lt;size_n;i++){
      printf("--- row: ---: %d\n", i+1);
      for(j=0;j&lt;size_m;j++){
          printf("--- col: ---: %d\n",j+1);
          p= &amp;t[i][j];
          do {
              printf("Book Type:%d Amount:%d\n", p-&gt;type, p-&gt;quantity);
              p= p-&gt;next;
          } while (p!=NULL);
      }
    }
  }
  </code></pre>
  
  <p>This is here my problem actually resides, I need to fix this insert function:</p>
  
  <pre><code>void insert(product **t, int id, int quantity)
  {
  product *p, *aux = NULL;
  p=&amp;t[0][0]; //doing it only in one position to test
  if((aux = malloc(sizeof(product))) == NULL)
      printf("Memory error\n");
  else
  {
      aux-&gt;type=id;
      aux-&gt;quantity=quantity;
      p-&gt;next = p; }
  p = aux;
  }
  </code></pre>
  
  <p>I need a remove book function too but I want to fix this problem first.
  Thanks in advice.</p>