memchr 函数文档
函数概要:
memchr 函数扫描 s 指向的内存空间的前 n 个字节,找到第一个匹配字符 c 时停止操作。
函数原型:
#include <string.h> ... void *memchr(const void *s, int c, size_t n);
参数解析:
|
参数 |
含义 |
|
s |
指向目标内存空间 |
|
c |
指向目标字符 |
|
n |
指定最大扫描字节数 |
返回值:
1. 如果找到该字符,则返回指向该字符的指针;
2. 如果找不到该字符,返回 NULL。
演示:
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[10] = "FishC.com";
char *ptr = NULL;
ptr = (char *)memchr(str, 'C', 10);
if (ptr != NULL)
{
printf("找到字符C!\n");
}
else
{
printf("找不到字符C!\n");
}
return 0;
}





