C string memchr() function
Example
Get a pointer to the first byte in a block of memory which contains a specified value:
char myStr[] = "Hello World!";
char *myPtr = (char*)memchr(myStr, 'o', 12);
if (myPtr != NULL) {
printf("%s", myPtr);
}
Try it Yourself »
Definition and Usage
The memchr()
function returns a pointer to the first byte in a block of memory which contains a specified value.
The memchr()
function is defined in the <string.h>
header file.
Syntax
memchr(void * pointer, int value, size_t size);
The size_t
data type is a positive integer.
Parameter Values
Parameter | Description |
---|---|
pointer | Required. A pointer to the block of memory to search in. |
value | Required. The value to search for. |
size | Required. The size of the block of memory to search in. |
Technical Details
Returns: | A void type pointer to the position in memory where the value was found or a NULL pointer if the value was not found. |
---|