Encoders
  Home  Forum  Guestbook  Email Us  About Us  Links  More Hub for Computer Whizzes Register to join us

C
C++
Security
Miscellaneous
Encoders > More... > C > Program 23

<< Previous  Next >>


/* Function strindex(s,t) which returns the position of the rightmost
   occurence of t in s, or -1 if there is none. */

#include <stdio.h>

int strindex(char s[], char t[]);

main()
{
        char a[]="hello world", b[]="orl";
        printf("%d\n",strindex(a,b));
}


int strindex(char s[], char t[])
{
	int i, j;
	for(i=0;s[i]!='\0';i++)
		;
        for(; i>=0 ; i= i-j-1)
	{
                for(j=0 ; s[i]!='\0' && t[j]!='\0' && s[i]==t[j]; ++i, ++j)
			;
                if(j>0 && t[j]=='\0')
			return i-j;
	}
	return -1;
}

 

encoders.20m.com - hosted at 20m.com
Site design and development by Susam Pal
-----------------------------------------------------