编辑代码

#include <stdio.h>
int main () {
	char s1[]="hello world";
    char s2[]="i";
    int len1=sizeof(s1);
    int len2=sizeof(s2);
    int i,j,x;
    for(i=0;i<len1;i++){
        x=0;
        if(s1[i]==s2[0]){
            for(j=0;j<len2-1;j++){
                if(s1[i+j]!=s2[j]){
                    break;
                }else{x++;}
            }
        }
        if(x==len2-1){
            printf("%d",i+1);
            break;
        }
    }if(x!=len2-1)
        printf("-1");
	return 0;
}