In this tutorial, We will learn about the strstr string function in C programming language and its functionality.
strstr() – In the c programming language, the strstr function is used to locate the first occurrence of the substring pointed by the str2 within str1 string.
Syntax for strstr() function is given below
char *strstr( const char *str1, const char *str2);
str1 – This string finds from str2
str2 – The substring from where its found.
The strstr() function pointer looks for the first occurrence of the substring(str2) within the string pointed by s1. If s2 can’t find it, it returns a null pointer.
the required header for strstr() String function in C Programming language
#include<string.h>
Program 1
“this is the best website for learning to code” is a string . “for” is a substring for find first occurrence in the string.
#include <stdio.h> #include <string.h> int main() { char myweb[100]="this is the best website for learning to code"; char *p; p=strstr(myweb,"for"); printf("%s\n",p); getch(); return 0; }
When above program me is compiled it will produce the following result
for learning to code
There are other C programming language functions that are similar to the this function
strncmp() function
strcat() function
strcpy() function
strncpy() function
Suggested for you
String handling in C language
String function in C Language
Function in C language
Arithmetic function in C language
Python code to Calculate sum of odd and even in a list In this tutorial,…
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…