名字
strchr, strrchr, strchrnul - 在字符串中定位一个字符
概要
#include <string.h>
char *strchr(const char *s, int c);
char *strrchr(const char *s, int c);
char *strchrnul(const char *s, int c); // 是GNU的扩展,不一定所以系统都支持
描述
strchr()函数返回一个指向在字符串s中第一个出现c的位置。
strrchr()函数返回一个指向在字符串s中最后一个出现c的位置。
strchrnul()函数同strchr相像,不同的是如果c没有在s中找到,则返回值指向的是在s的结尾的“the null byte”,而不是NULL。
例子
strchr.c
#include <string.h>
#include <stdio.h>
int main(int argc, const char *argv[])
{
char buf[100] = "I am lip!";
/*char *cp = NULL;*/
printf("%s\n", strchr(buf, 'a'));
return 0;
}
> ./a.out
> am lip!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)