CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;
//Returns a pointer to the first occurrence in str1 of any of the characters that are part of str2, or a null pointer if there are no matches.
//A pointer to the first occurrence in str1 of any of the characters that are part of str2, or a null pointer if none of the characters of str2 is found in str1 before the terminating null-character.
//If none of the characters of str2 is present in str1, a null pointer is returned.
char* Strpbrk(const char* s1,const char* s2)
{
const char*p1,*p2;
for(p1=s1; *p1; p1++)
{
for(p2=s2; *p2; p2++)
{
if(*p1 == *p2) // *p1 found in s2[]
{
return (char*)p1; // so returns its address
}
}
}
return NULL; // no character of s1 is in s2[]
}
int main()
{
char string1[80];
char string2[80];
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run