#include <string.h>
char *strchr(const char *s, int c);
The strchr() function returns a pointer to the first occurrence of the
character c in the string s.
函数返回字符c(这里的类型为int)在字符串s中的第一个位置。
#include <string.h>
int main()
{
char *s = "hello world";
char c = 'l';
if(strchr(s, c))
printf("01 %d, %c\n", s - strchr(s, c), *strchr(s, c));
c = 'a';
if(strchr(s, c))
printf("02 %d, %c\n", s - strchr(s, c), *strchr(s, c));
c = 0;
if(strchr(s, c))
printf("03 %d, %c\n", s - strchr(s, c), *strchr(s, c));
return 0;
}
结果: