C strstr() Function

Last Updated:

C strstr()

The strstr() function determines the first occurrence of a given string in another string.

Example

C Compiler
#include <stdio.h> #include <string.h> int main() { char str1[] = "wikimass is awesome and is good"; char str2[] = "is"; char *ret; ret = strstr(str1, str2); printf("substring: %s", ret); return 0; }

Syntax

char *strstr(char *str1, char *str2)

Parameter Values

ValueTypeExplanation
str1 Required Specifies the string 1
str2 Required Specifies the string 2

Return Value

ValueExplanation
Address Returns the pointer location from where the second string starts in the first string.
NULL If the second string was not found in the first string.

Share this Page

Meet the Author