Searches for an occurrence of a character in a character string.
#include <string.h> char *strchr(const char *s, int c);
s
The string to search.
c
The character to search for.
This function searches for the first occurrence of the character c in the character array pointed to by s. The function stops when it finds c or when it reaches the null character. The s argument must point to a null-terminated character array.
The function returns a pointer to the successfully located character. If it fails it returns a null pointer ( NULL).
This facility may not be available on some configurations of the EWL.
#include <string.h> #include <stdio.h> int main(void) { char s[] = "tree * tomato eggplant garlic"; char *strptr; strptr = strchr(s, '*'); if (strptr != NULL) puts(strptr); return 0; } Output: * tomato eggplant garlic