题目描述:字符串查找

来源:互联网 发布:android源码手册apk 编辑:程序博客网 时间:2024/05/29 04:13
要求:Write the function strindex(s,t) which returns the position of the rightmost occurrence of

t in s, or -1 if there is none.


the c programming language second edittion 


#include <stdlib.h>int strindex(char *src_str,char *dest_str){    int i,j,k;    int src_length=strlen(src_str)-1;    int dest_length=strlen(dest_str)-1;    for(i=src_length;i>=0;--i)    {        for(j=i,k=dest_length;k>=0&&dest_str[k]==src_str[j];--j,--k)            ;        if(k < 0)            return i-dest_length;    }    return -1;}main(){    char str1[20]="ABCDABSCD";    char str2[20]="CD";    printf("%d\n",strindex(str1,str2));}


批注:空循环用的好啊。

原创粉丝点击