这个代码怎么错了?C++

来源:百度知道 编辑:UC知道 时间:2024/06/17 21:00:34
#include <iostream>
using namespace std;

char * GetSubstr(char *sub, char *str)
{
//...请补充完整
}

int main()
{
char *substr;
substr=GetSubstr("two","One two three four five");
cout<<"找到的子串为:"<<substr<<endl;
return 0;
}
运行是死掉~~~
是下面这个。怎么错了??可以编译不能运行…………

#include <iostream>
using namespace std;

char * GetSubstr(char *sub, char *str)
{
int i=0,csub=0,cstr=0,x=0;
while(*(sub+i)!='\0')
{
csub++;
i++;
}
i=0;
while(*(str+i)!='\0')
{
cstr++;
i++;
}

for(i=0;i<cstr;i++)
{int j;
if(*(sub)==*(str+i))
{
for(j=0;j<csub;j++)
{x=0;
if(*(sub+j)!=*(str+i+j))
{break;}
else
{x++;}
}
if(x==csub)
{return str+i;break;}

函数都没有写,怎么会不死?substr未初始化指的地方未知,函数又没有用,它指向的地方要是是windows老大的地方它当然只能死了

Excel 2000本身不知何故,并不支持单条记录的输出,如果想把Excel 2000里的通讯录一条一条打出来,倒也成问题。来来来,且看我三板斧是如何让它乖乖就范的!

GetSubstr()函数是空的吗?那当然有问题啊,没有返回值啊