C function strchr - How to calculate the position of the character?
问题 I have this example code for the strchr function in C. /* 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); pch=strchr(pch+1,'s'); } return 0; } 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