Code:
#include
char* strpbrk(char *, char *);
int main()
{
char string1[50], string2[50];
char *pos;
printf("Enter the String:\n");
scanf(" %[^\n]s", string1);
printf("\nEnter the Character Set:\n");
scanf(" %[^\n]s", string2);
pos=strpbrk(string1, string2);
printf("%s", pos);
}
/* Locates First occurrence in string s1 of any character in string s2,
* If a character from string s2 is found ,
* a pointer to the character in string s1 is returned,
* otherwise, a NULL pointer is returned.
*/
char* strpbrk(char *string1, char *string2)
{
int i, j, pos, flag = 0;
for (i = 0; string1[i] != '\0';i++);
pos = i;
for (i = 0;string2[i] != '\0';i++)
{
for (j = 0;string1[j] != '\0';j++)
{
if (string2[i] == string1[j])
{
if ( j <= p1)
{
pos = j;
flag = 1;
}
}
}
}
if (flag == 1)
{
return &string1[pos];
}
else
{
return NULL;
}
}
Output:
Enter the String:
C programming Class
Enter the Character Set:
mp
programming Class
More C Programs