Linux库函数之strchr函数分析

strchr函数用于在字符串s中搜索字符c,如果找到了字符c,则返回指向字符c的指针,如果没有找到则返回null。函数实现如下:

290 /**

291  * strchr - Find the first occurrence of a character in a string
292  * @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 }
posted @ 2012-05-29 15:58  移动应用开发  阅读(419)  评论(0编辑  收藏  举报