【问题描述】编写一个函数strrindex(s,t),用于返回字符串t在字符串s中最右边出现的位置.该位置从0开始计数,如果s中不含有t,那么返回-1;在你编写的程序中,使用strrindex(s,t)函数,输入t,s,输出t在s最右边的位置. | |
#include<stdio.h>
#define M 100
void strrindex(char s[], char t[])
{
int i,j,k,r = -1;
for(i = 0; s[i] != '\0'; i++)
{
k = 0;
for(j = i; t[k] !='\0';j++,k++)
{
if(t[k] == s[j])
{
continue;
}
else
{
break;
}
}
if(t[k] == '\0')
r = i;
}
printf("%d",r);
}
int main()
{
char s[M];
char t[M];
gets(s);
gets(t);
strrindex(s,t);
return 0;
}