1: #include <stdio.h>
2: #include <string.h>
3: void *my_strstr(char *str1,char *str2)
4: {
5: int l1,l2;
6: l2 = strlen(str2);
7: if(!l2)
8: return (char *)str1;
9: l1 = strlen(str1);
10: while(l1>=l2)
11: {
12: l1--;
13: if ( !memcmp(str1,str2,l2))
14: {
15: return (char *)str1;
16: }
17: str1++;
18: }
19: return NULL;
20: }
21: main()
22: {
23: char str1[100] = "helloworld";
24: char str2[100] = "llo";
25: char *temp = my_strstr(str1,str2);
26: printf("%s\n",temp);
27: temp = strstr(str1,str2);
28: printf("%s\n",temp);
29: }
RTOS, Linux Kernel internal, OS-Programming C & Data Structures, Debugging, Optimizations, Makefiles and Wireless Technologies (Wi-Fi ,LTE and LTE-Advanced )
Search This Blog
Wednesday, October 28, 2015
write your own strstr function.
Labels:
C
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment