问题描述
- Index没有返回值是怎麽回事,求指导
-
#include
#include
#include
#define MAXSTLEN 234
typedef char SString[MAXSTLEN+1];
int Index(SString S,SString T,int pos)
{int i=pos,j=1,len1,len2;
len1=strlen(S);
len2=strlen(T);
while((i<=len1)&&(j<=len2))
{
if(S[i]==T[j])
{
++i;
++j;
}
else
{
i=i-j+2;
j=1;
}
}
if(j>len2)
return i-len2;
else return 0;
}
void main()
{ SString s,t;
cout<<"n请输入原字符串:";
cin>>s;
cout<<"n请输入模式串:";
cin>>t;
cout<<"n返回值为:";
Index(s,t,1);
cout<<endl;
}
解决方案
int r=Index(s,t,1);//你的把返回值返回输出才能看到
cout<<r<<endl;
解决方案二:
嗯,返回值需要打印出来。
时间: 2024-08-29 07:27:17