The word "memchr" is the short of Memory character. The C++ memchr() library Function is used to search a particular character (specified number of bytes) from a block of memory. This function returns a pointer to memory location if value found during search process. If value doesn't found, it returns null pointer.
Syntax Declaration for memchr()
In C++, the general syntax of this function is as follows:void var = memchr (ptr, chr, size);Where:
void | It is a C++ keyword. |
var | It indicates the pointer variable of void type. |
ptr | It represents the pointer to the block of memory where search is performed. The name of string variable is given here. |
chr | It represents the character to be searched from the buffer. |
size | It indicates the buffer size in bytes. |
memchr() Useage
The following program searches a character from the block of memory using memchr() function.
#include
#include
main()
{
void *ach;
char *aos;
char *str ="C++ Tutorials for Beginners";
ach = memchr (str, 'B', strlen(str));
aos = (char *) ach; //to convert pointer type void to char type
if (ach != NULL)
cout else
cout
return 0;
}