C strstr() Function

C strstr() Function

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
str1RequiredSpecifies the string 1
str2RequiredSpecifies the string 2

Return Value

ValueExplanation
AddressReturns the pointer location from where the second string starts in the first string.
NULLIf the second string was not found in the first string.

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author