#include
#include
using namespace std;
char *strfind(char *src, char *dst)
{
int len1 = strlen(src);
int len2 = strlen(dst);
int start = len1 - 1;
int end = len2 - 1;
int i,j = len2 - 1;
for(i = start;i >= end;i--)
{
if(src[i] == dst[j])
{
j--;
if(j == - 1)
{
cout << "the position is: " << i + 1 << endl;
return &src[i];
}
}
else
j = len2 - 1;
}
return NULL;
}
int main()
{
char src[100];
char dst[100];
cout << "请输入一个字符串:" << endl;
cin.getline(src,100,'\n');
cin.clear();
cout << "请输入要查找的字符串:" << endl;
cin.getline(dst,100,'\n');
if(strfind(src, dst) != NULL)
{
cout << "所寻找的字符串以及后面的字符串为:" << strfind(src, dst) << endl;
}
else
cout << "no such characters!" << endl;
system("pause");
return 0;
}
输出结果如下:
一:cin、cin.get()、cin.getline()、getline()、gets()等函数的用法: