C memchr() Function

Last Updated:

C memchr()

The memchr() function searches for the first occurrence of the character in a specified number of characters.


C Compiler
#include <stdio.h> #include <string.h> int main() { const char str[] = "John Doe R"; const char ch = ' '; char *lName; lName = memchr(str, ch, 6); printf("Last Name: %s", lName); return 0; }


void *memchr(const void *str, int ch, size_t n)

Parameter Values

str Required Specifies a string (block of memory) where the search is performed.
ch Required Specifies a character to search for.
n Required Specifies the number of bytes to be scanned.

Return Value

Address Returns a pointer to the matching byte.
NULL If the character does not occur in the given memory area.

Share this Page

Meet the Author