title: pointer to many structures in c
body: <p>I can have many sensors. Each sensor has an address, current and pressure. Due to the fact I don't know how many sensors there could be, I thought of creating a pointer to structs:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  struct sensor {
    unsigned long long int           address;
    float                            current;
    unsigned char                    pressure_units;
  };
  
  static struct sensor *sensors;
  
  struct sensor *createSensor(unsigned long long int address, float current, unsigned char pressure_units)
  {
    struct sensor *temp = malloc(sizeof(struct sensor));
    // (*temp).address
    temp-&gt;address = address;
    temp-&gt;current = current;
    temp-&gt;pressure_units = pressure_units;
    return temp;
  }
  
  void checkSerialHart(int sensorId)
  {
      sensors = createSensor(10000*sensorId,sensorId+3.0,sensorId);
  }
  
  int main(int argc, char *argv[])
  {
      int i, j;
      for(i=0,j=0;i&lt;3;i++)
      {
          // test case where sensor n doesn't respond
          if(i != 1)
          {
              checkSerialHart(j);
              ++j;
              ++sensors;
          }
      }
      printf("address: %llu current: %f pressure: %c\n", sensors[0].address, sensors[0].current, sensors[0].pressure_units);
      printf("address: %llu current: %f pressure: %c\n", sensors[1].address, sensors[1].current, sensors[1].pressure_units);
  }
  </code></pre>
  
  <p>I am having trouble keeping a pointer to structs where I can move through the pointer to get values of different sensors. The above prints this:</p>
  
  <pre><code>address: 580340276002816 current: 0.000000 pressure: 
  address: 0 current: 0.000000 pressure: 
  </code></pre>
  
  <p>But I expected this:</p>
  
  <pre><code>address:0,current:3.000000,pressure_units:0
  address:20000,current:5.000000,pressure_units:2
  </code></pre>
  
  <p>What may I be doing wrong?</p>