|
本帖最后由 VC-bigboss 于 2020-10-6 14:54 编辑
#include <iostream>
#include <string>
using namespace std;
char* get_same_string(char* p1, char* p2)
{
int c = 0, count = 0, idx = 0;
char* p = new char(0);
for (int i = 0; *(p1 +i)!='\0'; i++)
{
for(int j = 0; *(p1 + j) != '\0'; j++)
{
if (p1 == p2[j])
{
while (p1[i + c] == p2[j + c])
{
c++;
p[idx + c] = p1[i + c];
}
c = 0;
}
}
}
return p;
}
int main()
{
char a[] = "aabbcc", b[] = "kkbcyy";
char* pt = get_same_string(a, b);
cout << pt << endl;
return 0;
}
输出相同部分字符串,结果是什么都不输出。有人知道哪里出问题了吗? |
上一篇: 运行结果怎么如此奇怪?下一篇: 海外大学C++入门课练习题: Queue, Class, Stack
|