title: How to pass array index into another function in c
body: <p>I am trying to figure out how to pass an array index into another function.</p>
  
  <p>Here I have:</p>
  
  <pre><code> for(i=0; i&lt;file_cnt; i++){
  
            iret1 = pthread_create(&amp;(file[i]), NULL, get_checksum, (void*)&amp;filenames[i]);
            printf("%s\n", filenames[i]);
          }
  </code></pre>
  
  <p>In the function <code>get_checksum</code>, I eventually need the index of filenames, but <code>i</code> is not available in that function.</p>
  
  <p>In the <code>get_checksum</code> function, </p>
  
  <pre><code>void* get_checksum(void* a){
  
              char *filename = (char *) a;
  .....
  }
  </code></pre>
  
  <p>I passed in <code>a</code> as a char pointer in relation to <code>filenames[i]</code>.</p>
  
  <p>However, I need to make computations later in the function: <code>get_checksum</code>that involve getting the index of an array of sums. Therefore, I really need the index of <code>filenames</code> to be passed into the function <code>get_checksum</code> instead.</p>
  
  <p>Any suggestions how to pass an array index into another function?</p>