Header file:
string.h
Synopsis:
char *strstr(char *str, char *substr);
Description:
It returns pointer to the first occurrence of string substr in string str. NULL is returned, if string substr is not available in string str.
strstr function C example:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
char *str, *res;
str = (char *) malloc(100);
printf("enter your string:");
fgets(str, 80, stdin);
res = strstr(str, "blogspot"); // checks blogspot is substring of str
if (res == NULL)
printf("Substring absent\n");
else
printf("Substring present: %s\n", res);
return 0;
}
#include<stdlib.h>
#include<string.h>
int main() {
char *str, *res;
str = (char *) malloc(100);
printf("enter your string:");
fgets(str, 80, stdin);
res = strstr(str, "blogspot"); // checks blogspot is substring of str
if (res == NULL)
printf("Substring absent\n");
else
printf("Substring present: %s\n", res);
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
enter your string:see-programming.blogspot.in
Substring present: blogspot.in
enter your string:see-programming.blogspot.in
Substring present: blogspot.in
ReplyDeletenice article for beginners.thank you.
java string
java string