C - passing an array by reference - only first element set
<p>I have a function which should modify an array (of floats) in the original parent function. I am using the following code:</p>

<pre><code>void sortFunction(Word**words, int wordCount){ //to sure if two * are correct (pointer to an array..?)
int i = 0;
for(i=0;i&lt;wordCount-1;i++){
  Word first = *words[i]; //values fine
  Word second = *words[i+1]; //weird values, causes segfault
    if(first.data[0] &gt; second.data[0]){
      //do stuff
    }
  }
}

int main(int argc, char ** argv){
  Word* words = NULL;
  int wordsCount = ...
  //filling the array in a loop and using realloc for memory allocation
  //Here, the array is filled correctly (verified)
  sortFunction(&amp;words, wordsCount);
}
</code></pre>

<p>Where <code>Word</code> is a typedef struct and <code>Word.data</code> is the (dynamic) float array. When checking in the parent function, the array is allocated and the values set correctly.</p>

<p>I have tried with about 10 elements in the array, but always only the first ([0]) element is fine in the <code>sortFunction()</code>, second and all others are messed up. I also have an <code>int</code> propery in the struct, and when I try to print it for the second element, I get something over 1 billion.</p>

<p>I assume I am not passing the array correctly - I use the following code (just a sample) to pass regular variables, so I tried to modify it for an array, but apparently, not correctly. What is the right way to do this for an array?</p>

<pre><code>void foo(int*var){
  *var=8;
}

int main(){
  int var = 5;
  changeVar(&amp;var);
}
</code></pre>

<p>Thanks in advance for any tips!</p>