title: C function strchr - How to calculate the position of the character?
body: <p>I have this example code for the strchr function in C.</p>
  
  <pre><code>/* strchr example */
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int main ()
  {
    char str[] = "This is a sample string";
    char * pch;
    printf ("Looking for the 's' character in \"%s\"...\n",str);
    pch=strchr(str,'s');
    while (pch!=NULL)
    {
      printf ("found at %d\n",pch-str+1);
      pch=strchr(pch+1,'s');
    }
    return 0;
  }
  </code></pre>
  
  <p>The problem is, I don't understand, how this program calculates the position of the looking character.
  I think it has something to do with the pointers of "pch" and "str", but how does this work?</p>
  
  <p>Would be great, if there is somebody who could explain this in little more detail.
  <br></p>
  
  <p>thanks,
  eljobso</p>