C examples for string.h:memchr
<cstring> <string.h>
Locate character in block of memory.
function
const void * memchr ( const void * ptr, int value, size_t num ); void * memchr ( void * ptr, int value, size_t num );
Parameter | Description |
---|---|
ptr | Pointer to the memory block. |
value | Value to search. |
num | Number of bytes to cover. |
pointer to the first occurrence of value.
If not found, the function returns a null pointer.
#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; }