// strchr example // locate first occurrence of character in string // source: http://www.cplusplus.com/ #include #include #include int main() { char str[] = "Dartmouth CS students are simply the best hackers"; char *pch; printf ("Looking for the 's' character in \"%s\"...\n",str); pch=strchr(str, 's'); while (pch!=NULL) { fprintf(stdout, "found an 's' at location %d in the string\n", (int)(pch-str+1)); pch=strchr(pch+1,'s'); } return EXIT_SUCCESS; }