/* strchr example */
#include <stdio.h>
#include <string.h>
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);///what is this pch-str+1 doing?
pch=strchr(pch+1,'s');
}
return 0;
}
It is subtracting the address of str from pch then adding 1 to that result. Remember pch is a pointer to somewhere in the string whose starting address is str, this number should be the "index" value of the array.