memchr
void * memchr ( const void * buffer, int c, size_t num ); | string.h |
cplusplus.com |
Search buffer for a character.
Searches the first num bytes of memory block pointed by buffer for
character c.
Parameters.
Return Value.
A pointer to the first occurrence of c in buffer.
If character is not found the function returns NULL.
Portability.
Defined in ANSI-C.
ANSI-C++ standard specifies two different
declarations for this function instead of the one included in ANSI-C:
const void * memchr ( const void * buffer, int c, size_t num ); void * memchr ( void * buffer, int c, size_t num );Both have the same behavior as the original declaration.
Example.
/* memchr example */ #include <stdio.h> #include <string.h> main () { char * pch; char str[] = "Example string"; pch = (char*) memchr (str, 'l', strlen(str)); if (pch!=NULL) printf ("Character l was at position %d.\n", pch-str+1); else printf ("Character l was not found"); return 0; }Output:
See also.
memcmp,
memcpy,
memset,
strchr