新聞中心

        字符串倒序查找字串

        作者: 時(shí)間:2016-11-27 來源:網(wǎng)絡(luò) 收藏
        1. #include.h>
        2. #include<string.h>
        3. char*myStrrstr(constchar*haystack,constchar*needle);
        4. int
        5. main(void)
        6. {
        7. char*s="hello world";
        8. char*t="ll";
        9. char*r=myStrrstr(s,t);
        10. printf(r);
        11. return 0;
        12. }
        13. char*myStrrstr(constchar*haystack,constchar*needle)
        14. {
        15. unsigned int i;
        16. unsigned int hay_len,need_len;
        17. constchar*p;
        18. if(NULL==haystack||NULL==needle)
        19. returnNULL;
        20. hay_len=strlen(haystack);
        21. need_len=strlen(needle);
        22. if(need_len==0)
        23. return(char*)haystack;
        24. if(hay_len< need_len)
        25. returnNULL;
        26. p=haystack+hay_len-need_len;
        27. while(p>=haystack)
        28. {
        29. for(i=0;i< need_len;i++)
        30. if(p[i]!=needle[i])
        31. gotonext;
        32. return(char*)p;
        33. next:
        34. p--;
        35. }
        36. returnNULL;
        37. }


        關(guān)鍵詞: 字符串字

        評(píng)論


        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 津市市| 穆棱市| 江达县| 冷水江市| 蓬安县| 洪湖市| 平江县| 苗栗市| 贞丰县| 玉田县| 株洲市| 贡山| 宿迁市| 东方市| 鹿邑县| 忻城县| 蓝山县| 崇仁县| 普格县| 扶沟县| 仙游县| 芦溪县| 普宁市| 镇江市| 赤峰市| 泾川县| 巫溪县| 乌拉特后旗| 全椒县| 新河县| 柘荣县| 新竹市| 永寿县| 枣强县| 天门市| 江口县| 承德县| 朝阳市| 建水县| 大方县| 甘谷县|