title: assign value to member of struct pointer, within multiple struct pointers and arrays
body: <p>long title. but it is the exact problem i am having.
  it may be a misunderstanding of how the struct pointer works, or a problem using tthe correct format. i have the following typedefs of structs combined in a big 'box' for easy passing around the configuration.</p>
  
  <pre><code>typedef struct NTC_network{
       unsigned char NET_ID;      
       unsigned char DEV_ADDR;        
  }NTC_network;
  
  typedef struct NTC_io_trx_link{
    enum NTC_IO_LINK own_io;
    unsigned char ADDR;
    enum NTC_IO_LINK trx_io;
  }NTC_io_trx_link;
  
  //struct to hold status of I/O. 0==OFF 1==ON
  typedef struct NTC_config_stpio{
      unsigned char L1:1;
      unsigned char L2:1;
      unsigned char L3:1;
      unsigned char L4:1;
      unsigned char E1:1;
      unsigned char E2:1;
      unsigned char T1:1;
      unsigned char T2:1;
  }NTC_config_stpio;
  
  typedef struct NTC_header {
      unsigned char NET_ID;   
      unsigned char DST;      //destination address
      unsigned char SRC;      //source address
      unsigned char PCKT;             
  }NTC_header;
  
  typedef struct NTC_default_setup{
      unsigned char DEFAULT_SETUP:1;
  }NTC_default_setup;    
  
  typedef struct NTC_data{    
      unsigned char E1;       //resistor value to emulate on E1
      unsigned char E2;       //resistor value to emulate on E2
      unsigned char T1;       //resistor value of temperature sensor on T1
      unsigned char T2;       //resistor value of temperature sensor on T2
      unsigned char D1;       //230VAC detection circuit on/off
      unsigned char D2;       //230VAC detection circuit on/off       
      unsigned char ALRM;     //alarm on off 0xFF=alarm on, 0x00=alarm off            
  }NTC_data;
  
  typedef struct NTC_ack{
      unsigned char ACK;      //ACK field 0x00=no ack 0xFF= ack
  }NTC_ack;
  
  typedef struct NTC_config {
      NTC_default_setup *DEFAULT_STP;
      NTC_config_stpio *STPIO;
      NTC_config_network *NETWORK;
      NTC_io_trx_link *NTC_link_io;               
  }NTC_config;
  
  //struct for payload to send via LoRa
  typedef struct NTC_payload{
      NTC_header *Header;
      enum NTC_dc DC; 
      NTC_config *Config;
      NTC_data *Data;
      NTC_ack *Ack;   
  }NTC_payload;
  
  typedef struct NTC_runtime_data{
      NTC_payload *pPayload;  
  }NTC_runtime_data; 
  </code></pre>
  
  <p>and allocating the whole thing at runtime as such:</p>
  
  <pre><code>NTC_runtime_data* init_struct_runtime_data(void){   
  
      NTC_runtime_data *DATA = calloc(1, sizeof(NTC_runtime_data));   
  
      DATA-&gt;pPayload = calloc(2, sizeof(NTC_payload));
      for(int i = 0 ; i &lt; 2; i++){
          DATA-&gt;pPayload[i].Header = calloc(1, sizeof(NTC_header));
          DATA-&gt;pPayload[i].DC = NONE; 
          DATA-&gt;pPayload[i].Config = calloc(1, sizeof(NTC_config));
          DATA-&gt;pPayload[i].Config-&gt;DEFAULT_STP = calloc(1, sizeof(NTC_default_setup));
          DATA-&gt;pPayload[i].Config-&gt;STPIO = calloc(1, sizeof(NTC_config_stpio));      
          DATA-&gt;pPayload[i].Config-&gt;NETWORK = calloc(1, sizeof(NTC_config_network));
          DATA-&gt;pPayload[i].Config-&gt;NETWORK-&gt;NTC_NETWORK = calloc(1, sizeof(NTC_network));
          DATA-&gt;pPayload[i].Config-&gt;NTC_link_io = calloc(11, sizeof(NTC_io_trx_link));
          for(int j = 0; j &lt; 11; j++){
              DATA-&gt;pPayload[i].Config-&gt;NTC_link_io[j].own_io = j + 1;
          }           
          DATA-&gt;pPayload[i].Data = calloc(1, sizeof(NTC_data));
          DATA-&gt;pPayload[i].Ack = calloc(1, sizeof(NTC_ack));
      }
      return DATA;
  }
  </code></pre>
  
  <p>i am allocating 2 pPayload. one for TX data and one for RX.
  all this works fine and there is no problem what so ever assigning values like so:</p>
  
  <pre><code>    NTC_runtime_data *pDATA;
      pDATA = init_struct_runtime_data();
  </code></pre>
  
  <p>and then where ever i might pass this struct i can assign as follows:</p>
  
  <pre><code>pData-&gt;pPayload[0].Header-&gt;NET_ID = 0x20;
  </code></pre>
  
  <p>but i am having problems with trying to assign from a struct containing an array as a buffer which looks like this:</p>
  
  <pre><code>typedef struct TRX_buffer{
      size_t used;
      size_t size;
      unsigned char *array;
  }TRX_buffer;
  </code></pre>
  
  <p>and initializing and reallocating as so:</p>
  
  <pre><code>TRX_buffer* init_struct_trx_buffer(void){
      TRX_buffer *trx_buffer = malloc(sizeof(TRX_buffer));
      trx_buffer-&gt;array = malloc(4 * sizeof(unsigned char));
      trx_buffer-&gt;size = 4;
      trx_buffer-&gt;used = 0;
      return trx_buffer;
  }
  //inserts a byte of data in the buffer and dynamically allocates the buffer
  void insert_array(TRX_buffer *trxbuffer, unsigned char data){
      if(trxbuffer-&gt;used == trxbuffer-&gt;size){
          trxbuffer-&gt;size *= 2;
          trxbuffer[0].array = realloc(trxbuffer[0].array, trxbuffer-&gt;size * sizeof(unsigned char));
      }
      trxbuffer[0].array[trxbuffer-&gt;used] = data;
      trxbuffer-&gt;used++;
  }
  </code></pre>
  
  <p>so the problem is, some where in my program ,in a function, where i am creating a new instance of the buffer and load data from the radio, which i can see when debugging, i want to load it to my struct and i do it like this</p>
  
  <pre><code>NTC_payload* get_payload(NTC_payload *pPayload){    
      TRX_buffer *rx_buffer;
      rx_buffer = init_struct_trx_buffer();
  
      r_FIFO(rx_buffer);
  
      pDATA-&gt;pPayload[1].Header-&gt;NET_ID = trx_buffer-&gt;array[0];
  </code></pre>
  
  <p>the correct data is in the <code>trx_buffer</code> after my <code>r_FIFO()</code> function. but this isn't working. i have tried different methods. but cant get it to take the value from my buffer and assign it to my struct.</p>
  
  <p>what is wrong??</p>