Strstr function : Finds first occurrence of sub-string in other string
Features :
- Finds the first occurrence of a sub string in another string
- Main Purpose : Finding Substring
- Header File : String.h
- Checks whether s2 is present in s1 or not
- On success, strstr returns a pointer to the element in s1 where s2 begins (points to s2 in s1).
- On error (if s2 does not occur in s1), strstr returns null.
Syntax :
char *strstr(const char *s1, const char *s2);
#include<stdio.h>
#include<string.h>
int main(void)
{
char *str1 = "c4learn.blogspot.com", *str2 = "spot", *ptr;
ptr = strstr(str1, str2);
printf("The substring is: %s\n", ptr);
return 0;
}
Output :
The substring is: spot.com
Live Example 2: Passing Direct Strings
#include<stdio.h>
#include<string.h>
void main()
{
char *ptr;
ptr = strstr("c4learn.blogspot.com","spot");
printf("The substring is: %s\n", ptr);
}
Output :
The substring is: spot.com

0 comments:
Post a Comment
Your Feedback : This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email