strstr in C
strstr is a function in C that is used to find the first occurrence of a substring in a string. It is declared in the <string.h> header.Syntax:
char *strstr(const char *str1, const char *str2);
- str1 → The main string in which you want to search.
- str2 → The substring you are searching for.
Returns:
- A pointer to the first occurrence of str2 in str1.
- NULL if str2 is not found.
Example:
//String Processing using strstr function.
#include<stdio.h>
#include<string.h>
int main()
{
char str1[10]="12345", str2[10]="23";
int n;
n=strstr(str1,str2);
puts(n);
return 0;
}
Output:
2345
No comments:
Post a Comment