I want to have a function that returns an index of first occurrence of a char t in char s. My attempt, which is obviously wrong,is:
int f(char* s, char* t){
int a = strlen(t);
int counter=0;
for(int i=0; t[i]!=0; i++){
for(int j=0; s[j]!=0; j++){
if(t[i]==s[j]){
}
break;
}
}
return j;
}
I wanted to find a first letter of char t in char s and then check whether next letter is identical in char s as in char t. And then return an index e.g. f("abaabb", "bb")=4
.
I would prefer to keep this as simple as possible, nothing sophisticated to do this should be required. If this question could be improved please tell me how could i make it better?
Aucun commentaire:
Enregistrer un commentaire