A
Aenima1891
Write the function strrindex(s,t) , which returns the position of the
rightmost occurrence of t in s , or -1 if there is none.
Here's my stuff, why doesn't work??!?
#include <stdio.h>
int strindex(char s[], char t[]);
int main(void)
{
char s[]="mamma mia come sto";
char t[]= "come";
printf("%d", strindex(s, t));
return 0;
}
int strindex(char s[], char t[])
{
int i, j, k;
for(i= strlen(s)-1; i >= strlen(t)-1; i--) {
for(j = i, k = strlen(t)-1; s[j] == t[k] && k>=0; j--, k--)
;
if(k == 0)
return i;
}
return -1;
}
rightmost occurrence of t in s , or -1 if there is none.
Here's my stuff, why doesn't work??!?
#include <stdio.h>
int strindex(char s[], char t[]);
int main(void)
{
char s[]="mamma mia come sto";
char t[]= "come";
printf("%d", strindex(s, t));
return 0;
}
int strindex(char s[], char t[])
{
int i, j, k;
for(i= strlen(s)-1; i >= strlen(t)-1; i--) {
for(j = i, k = strlen(t)-1; s[j] == t[k] && k>=0; j--, k--)
;
if(k == 0)
return i;
}
return -1;
}