程序代码:
#include<iostream>
#include<stdlib.h>
using namespace std;
char * Getsubstr(char * sub,char *str)
{
int flag = 0;
char * s;
s = sub;
//cout<<"str : sub:"<<strlen(str)<<"\t"<<strlen(sub)<<endl;
while(*str != '\0')
{
while(*sub != '\0')
{
if(* str == *sub )
{
str++;
sub++;
flag++;
// cout<<flag<<"\t";
}//end of if
else
{
if(flag)
{
while(flag > 0)
{
sub--;
str --;
flag--;
}
//str ++;
}
str++;
}
if(flag == strlen(s))
{
// cout<<flag<<endl;
return str;
}
} //end of while
}//end of while
if(* str == '\0')
return NULL;
}
int main()
{
char * s1 = new char[];
char *s2 = new char[];
char * p,*q;
p = s2;
cout<<"输入一个完整字符串:"<<"输入一个字串:"<<endl;
gets(s1 );
gets(s2);
int i = strlen(s1);
int flag = strlen(s2);
q = Getsubstr(s2,s1);
// if(q)
// {
while(flag > 0)
{
q--;
flag --;
}
//cout<<s2;
cout<<q<<endl;
// }
//else
// cout<<"不"<<endl;
cout<<"ok"<<endl;
return 0;
}
当前存在问题:
1.getstrsub()函数存在没有返回值得情况
总结:
当前程序并不完善,需要进一步改进。
本文深入探讨了程序代码中的字符串查找与匹配函数实现细节,包括存在的问题与优化方案,旨在提升开发者对于底层代码的理解与实践能力。
92

被折叠的 条评论
为什么被折叠?



