#include #include int main () { const char * haystack = "Giant Haystack"; int pos = 'a'; const char * location; location = haystack; while (1) { location = strchr (location, pos); /* strchr returns NULL (0) if the character is not found. */ if (! location) { puts ("End of string."); break; } printf ("Found %c at position %d\n", pos, location - haystack); /* Skip over this character and start looking again. */ location++; } /* Now go right to left. */ location = haystack; location = strrchr (location, pos); /* strrchr returns NULL (0) if the character is not found. */ if (! location) { printf ("%c was not found.", pos); } else { printf ("Found rightmost %c at position %d\n", pos, location - haystack); } return 0; }