title: Find index of pointer array in C
body: <p>I am looking at something with a pointer that is acting like a buffer for data with an array size of about 800. It is looping and placing sets of data in order at various indexes.</p>
  
  <p>Say we have 1001 and a space then 0110 it will then fill the buffer with "1001 0110 1001 0110 1001" and so on...</p>
  
  <p>So what I want to do is find the index it is currently at and change it say from "1001 0110" to something like "0101 0110 0101 0110". </p>
  
  <p>So, basically I want to find the index of the buffer and change the data inside before it goes to its output routine. </p>
  
  <p>Here is what something like I am looking at:</p>
  
  <pre><code>char *p1;
  char p2[800];
  int setIndex = 0;
  
  if (p1 &gt;= &amp;p2[p2_length - 1]) p1 = &amp;p2[0];
  else ++p1;
  </code></pre>
  
  <p>What do I set "setIndex" to in order to change the value at where ever p2 is? ex: p2[setIndex], what is setIndex? Do I just set setIndex to the pointer address value or the value at that address? I'm a bit confused. Thank you.</p>
  
  <p>edit:</p>
  
  <p>Answer that worked for me thanks to Barmar.</p>
  
  <pre><code>setIndex = p1 - p2;
  
  p2[setIndex] = '1'; //or whatever value you want to change to
  </code></pre>