Searches for a character array within another.
#include <string.h> char *strstr(const char *s1, const char *s2);
s1
A pointer to the string to search in.
s2
A pointer to the string to search for.
This function searches the character array pointed to by s1 for the first occurrence of the character array pointed to by s2. Both s1 and s2 must point to null-terminated character arrays.
The function returns a pointer to the first occurrence of s2 in s1 and returns a null pointer ( NULL) if s2 cannot be found.
This facility may not be available on some configurations of the EWL.
#include <string.h> #include <stdio.h> int main(void) { char s1[] = "tomato carrot onion"; char s2[] = "on"; const char* found; found = strstr(s1, s2); if (found != NULL) puts(found); return 0; } Output: onion