Strchr
defined in header file <string.h>
Char *strchr (const char *STR, int ch);
look for the first occurrence of CH (converted to char as (char) ch) in the null-terminated byte string pointed to by STR (each character is considered to be a unsigned char). The terminating null character is considered to be part of the string and can be found when searching for ' + '.
If STR is not a pointer to a null-terminated byte string, the behavior is undefined.
Parameters
STR-pointer to the null-terminated byte string to be parsed
CH-the character to find
return value
A pointer to the character found by STR, which returns a null pointer when the word is not found.
Example
/* STRCHR Example */#include <stdio.h> #include <string.h>int main () { char str[] = "This is a sample Strin G "; 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;}
Found at 18*/
Strrchr
Defined in header file <string.h>
const char *STRRCHR (const char *STR, int ch);
Char *strrchr (char *str, int ch);
Find the last occurrence of the character ch in the byte string pointed to by Str.
Parameters
Str-null a pointer to the end of a byte string for analysis
CH-Search Characters
return value
STR, or NULL to find a pointer to the character if no such character is found
Example
/* STRRCHR Example */#include <stdio.h> #include <string.h>int main () { char str[] = "This is a sample stri Ng "; char * PCH; PCH=STRRCHR (str, ' s '); printf ("Last occurence of ' s ' found at%d \ n", pch-str+1); return 0;} /*last occurence of ' s ' found at 18 * *
STRCHR () function and STRRCHR () function