函数指针查找剩余子串
char* match(char* ch, char c);
int main()
{
char ch[50], c, * p;
int pos = 0;
cin.getline(ch, 20);
cin >> c;
p = match(ch, c);
if (p)
{
pos = strlen(ch) - strlen(p) + 1;
cout << "sizeof(ch)=" << sizeof(ch);
cout << ", sizeof(p)=" << sizeof(p) << endl;
cout << "p=" << p << ",pos=" << pos << endl;
}
else
{
cout << "no match found\n";
}
cout << endl;
return 0;
}
char* match(char* ch, char c)
{
int count = 0;
while (c != ch[count] && ch[count] != '\0')
count++;
if (ch[count])
{
return &ch[count];
}
return nullptr;
}
/*
input:
this is a word
o
output:
sizeof(ch)=50, sizeof(p)=4
p=ord,pos=12
*/