我的任务是编写我自己的 strchr 版本,但它似乎不起作用。任何建议将不胜感激。这里是:
char *strchr (const char *s, int c) //we are looking for c on the string s
{
int dog; //This is the index on the string, initialized as 0
dog = 0;
int point; //this is the pointer to the location given by the index
point = &s[dog];
while ((s[dog] != c) && (s[dog] != '\0')) { //it keeps adding to dog until it stumbles upon either c or '\0'
dog++;
}
if (s[dog]==c) {
return point; //at this point, if this value is equal to c it returns the pointer to that location
}
else {
return NULL; //if not, this means that c is not on the string
}
}