Vote count:
0
I am supposed to loop through the character of arrays that is passed in and look for the first occurrence of char, then return the index of the first occurrence. if char is not found then I return -1. This seems to work for all characters except the character at 0, which it does not find for some reason.
int find_ch_index(char string[], char ch) {
int i = 0;
while (string[i++]) {
if (string[i] == ch) {
return i;
}
}
return -1;
}
asked 47 secs ago
Find the first index of a character in a string
Aucun commentaire:
Enregistrer un commentaire