📅  最后修改于: 2020-09-25 09:03:33             🧑  作者: Mango
const void* memchr( const void* ptr, int ch, size_t count );
void* memchr( void* ptr, int ch, size_t count );
memchr()
函数采用三个参数: ptr
, ch
和count.
它首先将ch
转换为无符号char,并将其首次出现在ptr
指向的对象的第一个计数字符中。
它在
如果找到了字符 ,则memchr()
函数将返回一个指向字符位置的指针,否则返回空指针。
#include
#include
using namespace std;
int main()
{
char ptr[] = "This is a random string";
char ch = 'r';
int count = 15;
if (memchr(ptr,ch, count))
cout << ch << " is present in first " << count << " characters of \"" << ptr << "\"";
else
cout << ch << " is not present in first " << count << " characters of \"" << ptr << "\"";
return 0;
}
运行该程序时,输出为:
r is present in first 15 characters of "This is a random string"