Linux库函数之strchr函数分析
strchr函数用于在字符串s中搜索字符c,如果找到了字符c,则返回指向字符c的指针,如果没有找到则返回null。函数实现如下:
290 /**
291 * strchr - Find the first occurrence of a character in a string292 * @s: The string to be searched
293 * @c: The character to search for
294 */
295 char *strchr(const char *s, int c)
296 {
297 for (; *s != (char)c; ++s)
298 if (*s == '\0')
299 return NULL;
300 return (char *)s;
301 }