![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
#include <iostream.h>
#include <stdio.h>
/*
使用循环计算字符串长度
*/
int strlen(char *str)
{
int i;
for(i=0;str[i]!='\0';i++);
return i;
}
/*
在字符串中找寻字符串
*/
int strindex(char *str,char *substr)
{
int end,i,j;
end=strlen(str)-strlen(substr);//计算结束位置
if(end>0)
{
for(i=0;i<=end;i++)
{
for(j=i;str[j]==substr[j-i];j++)
{
if(substr[j-i+1]=='\0')
return i+1;
}
}
}
return -1;
}
void main()
{
char *str="abcdefghj";
char *substr="def";
cout<<strindex(str,substr)<<endl;
}