memchr - C string.h

C examples for string.h:memchr

From

 
<cstring> 
<string.h>

Description

Locate character in block of memory.

Type

function

Prototype

const void * memchr ( const void * ptr, int value, size_t num );
      void * memchr (       void * ptr, int value, size_t num );

Parameters

Parameter Description
ptr Pointer to the memory block.
value Value to search.
num Number of bytes to cover.

Return Value

pointer to the first occurrence of value.

If not found, the function returns a null pointer.

Demo Code


#include <stdio.h>
#include <string.h>

int main ()//from  w  w  w  .j a  va  2 s . c  om
{
  char* pch;
  char str[] = "this is a test Example string";
  pch = (char*) memchr (str, 'p', strlen(str));
  if (pch!=NULL)
    printf ("'p' found at position %d.\n", pch-str+1);
  else
    printf ("'p' not found.\n");
  return 0;
}

Related Tutorials