最簡單的字符串查找
int find(char* str, char* sub){//str2 字串
int i=0, j=0;
int s1=strlen(str), s2=strlen(sub);//sizeof(str)=4
while(i<s1 && j<s2){
if(str[i++]==sub[j++])
continue;
else{
i=i-j+1; j=0;
}
}
if(j==strlen(sub))
return i-j;
else return -1;
}
int i=0, j=0;
int s1=strlen(str), s2=strlen(sub);//sizeof(str)=4
while(i<s1 && j<s2){
if(str[i++]==sub[j++])
continue;
else{
i=i-j+1; j=0;
}
}
if(j==strlen(sub))
return i-j;
else return -1;
}
posted on 2008-10-28 10:20 deep2 閱讀(199) 評論(0) 編輯 收藏 引用 所屬分類: 字符串