Encoders
Hub for Computer Whizzes Register to join us

Encoders > More... > C > Program

/* Function any(s1,s2) that returns the first location in the first string
   where any character from the second string occurs, or -1 if the first
   string contains no characters from the second string. */

#include <stdio.h>

int any(char string1[], char string2[]);

main()
{
        char a[]="abcdef", b[]="peg";
        printf("%d\n",any(a,b));
}

int any(char s1[], char s2[])
{
	int i,j;
	for(i=0; s1[i]!='\0'; i++)
		for(j=0; s2[j]!='\0'; j++)
			if(s1[i]==s2[j])
				return i;
	return -1;
}