Mega Code Archive

 
Categories / C / Code Snippets
 

Find character in string how to use strchr

#include <stdio.h> #include <string.h> int main () { char str[] = "I am Superman"; char *j; printf ("Looking for 's' character in \"%s\"...\n", str); j = strchr(str, 's'); while (j != NULL) { printf ("found at %d\n",j - str + 1); j = strchr(j + 1, 's'); } return 0; }