Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

What is memchr() Function in C++

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;

 }






This post first appeared on Programming Explain, please read the originial post: here

Share the post

What is memchr() Function in C++

×

Subscribe to Programming Explain

Get updates delivered right to your inbox!

Thank you for your subscription

×