C memchr() Function

You are Here:

C memchr() Function

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

Example

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; }

Output

Last Name: Doe R

Syntax

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

Parameter Values

ValueTypeExplanation
strRequiredSpecifies a string (block of memory) where the search is performed.
chRequiredSpecifies a character to search for.
nRequiredSpecifies the number of bytes to be scanned.

Return Value

ValueExplanation
AddressReturns a pointer to the matching byte.
NULLIf the character does not occur in the given memory area.

Reminder

Hi Developers, we almost covered 98% of String functions and Interview Question on C with examples for quick and easy learning.

We are working to cover every Single Concept in C.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author