memchr() - Buffer Manipulation Function

How to scan / search memory for characters in C++?


memchr() memory manipulation function searches / scans the of the array "buffer" for first occurence of the character "ch" in the first "count".


void * memchr( void * buffer, int ch, size_t count );

Example :

#include <stdio.h>
#include <string.h>
int main ()
char str1[] = "United";
if( memchr(str1,'a',strlen(str1)) == NULL )
printf( "Character a not found\n" );
printf( "Found a\n" );
return 0;

Result :

Character a not found

In the above example, "memchr()" manipulation function is used to check if "a" is found in the "str1". It is done by scanning / searching the memory for the specified symbol.

C++ Tutorial

Ask Questions

Ask Question