- #include.h>
- #include<string.h>
- char*myStrrstr(constchar*haystack,constchar*needle);
- int
- main(void)
- {
char*s=”hello world”; char*t=”ll”; char*r=myStrrstr(s,t); printf(r); return 0; - }
- char*myStrrstr(constchar*haystack,constchar*needle)
- {
unsigned int i; unsigned int hay_len,need_len; constchar*p; if(NULL==haystack||NULL==needle) returnNULL; hay_len=strlen(haystack); need_len=strlen(needle); if(need_len==0) return(char*)haystack; if(hay_len< need_len) returnNULL; p=haystack+hay_len-need_len; while(p>=haystack) { for(i=0;i< need_len;i++) if(p[i]!=needle[i]) gotonext; return(char*)p; next: p–; } returnNULL; - }
字符串倒序查找字串
includeh>includespanstyle=color:FF0000;>stringh>char*myStrrstr(constchar*haystack,constchar
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/moni/257723.html