#include <stdio.h>
/*
strrindex这个函数返回字符串t在s中最右边出现的位置.如果s中不包含t,则返回-1.
*/
int comp_s(const char *s,const char *t)
{ /*如果s包含t则返回1,否则返回0 */
for(; *t !='/0' ;t++){
if(*t !=*(s++))
return 0;
}
return 1;
}
int strrindex(const char *s,const char *t)
{
const char *s_iter=s, *t_iter=t;
int index =-1;
while(*s_iter !='/0')
s_iter++,index++;
s_iter--;
while( s_iter-- != s){
index--;
if( *s_iter ==*t)
if( comp_s( s_iter,t) )return index;
}
return -1;/* s中不包含t */
}
int main()
{
char *a="asdkfjwieofjwieojfwjfe";
char *b="i";
printf("%d/n",strrindex(a,b));
return 0;
}