title: Iterate through int array of unknown length
body: <p>I am trying to iterate through an array that will contain <strong>up to</strong> a maximum of 4 elements - no other knowledge of the array-length exists.</p>
  
  <p><strong>Pseudo Code</strong></p>
  
  <pre><code>void insert_vals(uint8_t num, uint8_t *match_num, uint8_t *value)
  {
      uint8_t i;
  
      while(data_exists)  // how do I determine if data exists in 'value'?
      {
          switch(num)
          {
              case 0:
              {
                  switch(match_num[i])
                  {
                      case 0:
                          hw0reg0 = value[i];
                      case 1:
                          hw0reg1 = value[i];
                      case 2:
                          hw0reg2 = value[i];
                      case 3:
                          hw0reg3 = value[i];
                  }
              }
              case 1:
              {
                  switch(match_num[i])
                  {
                      case 0:
                          hw1reg0 = value[i];
                      case 1:
                          hw1reg1 = value[i];
                      case 2:
                          hw1reg2 = value[i];
                      case 3:
                          hw1reg3 = value[i];                 
                  }
              }
              // etc. 2 other cases
          }
          i++;
      }
  }
  </code></pre>
  
  <p><strong>Calling Example (Pseudo Code)</strong></p>
  
  <pre><code>/*
   * num: hardware device select from 1 - 4
   * match_num: 4 possible matches for each hardware device
   * value: 32-bit values to be assigned to 4 possible matches
   * NOTE: This function assumes hardware devices are selected
   * in a consecutive order; I will change this later.
   */
  
   // example calling code - we could have configured 4 hardware devices
   insert_vals(0, [0, 1], [0x00000001, 0x000000FF]);  // arg2 and arg3 equal in length
  </code></pre>
  
  <p>How can I accomplish this? </p>
  
  <p>In a character array, C will automatically add <code>'\0'</code> to the end of the array, but this does not seem to be the case for an integer array. If I  was somehow able to determine the length of <code>match_num</code> and <code>value</code> (see <code>if</code> statement) at runtime originally, then that would allow me to create a <code>for</code> loop.</p>
  
  <h1>Edit</h1>
  
  <p>Since I know that there will be a maximum of 4 elements, couldn't I do something similar to the following?</p>
  
  <pre><code>void insert_vals(uint8_t num, uint8_t *match_num, uint32_t *value)
  {
      int i;
  
      for(i = 0; i &lt; 4; i++)
      {
          if(value[i] == -1)
              break;
          else
          {
              // Assign data
          }
      }
  }
  </code></pre>