Pre-define String function in C

strstr string function in C programming language

strstr string function in C programming language

In this tutorial, We will learn about the strstr string function in C programming language and its functionality.

Description

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.

Declaration

Syntax for strstr() function is given below

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

parameter or argument

str1 – This string finds from str2

str2 – The substring from where its found.

Returns

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.

Required Header

the required header for strstr() String function in C Programming language

#include<string.h>

Example

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

strrchr string function in C programming Language
strcmp string function in C programming Language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

1 hour ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

3 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago