The strstr () function in C
Char * function strstr (const char * haystack, const char * needle) looks for the final occurrence of the whole needle string (not including the ending null character) that is present in the haystack string.
Char * function strstr (const char * haystack, const char * needle) looks for the final occurrence of the whole needle string (not including the ending null character) that is present in the haystack string.
Declaring the function strstr () in C
Here is the declaration for strstr () in C:
char * strstr ( const char * haystack , const char * needle )
Parameters
haystack - Chain to be scanned.
needle - A small string to be searched inside the haystack chain.
Returns the value
This function returns a pointer to the first occurrence in the haystack string of any sequence of characters defined in the needle, or function that returns a null pointer if this sequence is not present in haystack.
For example
The following C program illustrates the usage of strstr () in C:
#include #include int main () { const char haystack [ 20 ] = "QTMTeam" ; const char needle [ 10 ] = "Team" ; char * ret ; ret = strstr ( haystack , needle ); printf ( "Chuoi con la: %sn" , ret ); return ( 0 ); }
Compiling and running the above C program will result:
According to Tutorialspoint
Previous lesson: strspn () function in C
Next lesson: Strtok () function in C
You should read it
- Memset () function in C
- The strrchr () function in C
- Strcpy () function in C
- Memmove function in C
- The strcoll () function in C
- Function strxfrm () in C
- The function strcmp () in C
- The function strncmp () in C
- The function strpbrk () in C
- The strtok () function in C
- Strcat function in C
- The strlen () function in C
Maybe you are interested
Revealing new findings about the size of the galaxy Admire incredibly detailed images of the Orion Nebula through the eyes of the James Webb telescope This star 'tears up' its companion to create a rare beautiful nebula Galaxy merger moment gives glimpse into Milky Way's future Science has discovered the fastest-flying star in the Milky Way, reaching 8% of the speed of light Discovered organic molecules that can make life in the center of the Milky Way