title: Pointer to struct inside a struct; How to access without errors?
body: <p>As far as I know, if the item inside a structure is a pointer, you call it with <code>-&gt;</code>, if it's a normal value it is used <code>.</code>. </p>
  
  <p>here my typedefs:</p>
  
  <pre><code>typedef struct
  {
      char name[50];
      int quantity;
  }ing;
  
  typedef struct
  {
      char name[50];
      ing *n;
      int price, n_ing, max_producity;
  }prod;
  </code></pre>
  
  <p>then I declare a <code>prod a;</code> and I allocate <code>a-&gt;n=malloc(n*sizeof(ing));</code>. 
  But when I try to access to <code>a.n-&gt;name</code> it gives me error. </p>
  
  <p>All the 4 combinations gives me error "error: invalid type argument of '->' (have 'prod' (or 'ing'))" or "error: subscripted value is neither array nor pointer nor vector".</p>
  
  <p>Why?</p>
  
  <hr>
  
  <pre><code>    int ret_max_producity(prod a, ing n, int dim_n)
      {
          int max_prod=32100, i;
          for(i=0; i&lt;a.n_ing; i++)
          {
  /* here!-&gt;*/if((n[find_ing(n, a.n[i]-&gt;name, dim_n)].quantity)/(a.n-&gt;quantity)&lt;max_prod)
              {
  /* here!-&gt;*/    max_prod=(n[find_ing(n ,a.n[i]-&gt;name, dim_n)].quantity/a.n-&gt;quantity);
              }
          }
          if(max_prod==32100)
          {
              printf("ERROR WHILE FINDING MAX PRODUCITY FOR PRODUCT %s, ABORTING", a.name);
              system("pause");
              exit(EXIT_FAILURE);
          }
          return max_prod;
      }
  </code></pre>
  
  <hr>
  
  <pre><code>int find_ing(ing v, char *s, int dim)
  {
      int i;
      for(i=0; i&lt;dim; i++)
      {
          if(strcmp(s, v.name)==0)
          {
              return i;
          }
      }
      printf("\n\nERROR WHILE FINDING INGREDIENT %s IN VECTOR, ABORTING...", s);
      system("pause");
      exit(EXIT_FAILURE);
  }
  </code></pre>
  
  <hr>
  
  <p><img src="https://i.stack.imgur.com/oYWyr.png" alt="The errors"></p>