C Standard Libraries C++

memchr()

Declaration

void* memchr(const void* kvpBuffer, int iChar, size_t qCount);

Description

This function searches the first "qCount" characters of "kvpBuffer" for the first occurence of the character "iChar." If the function successfully finds that character, it returns a pointer to it. Otherwise, it returns NULL.

Example

#include <cstdio>
#include <cstring>

int main()
{
    char caBuffer[] = "XoaX.net";
    void* vpPtr = memchr(caBuffer, 'e', 8);
    printf("Found character: %c\n", *((char*)(vpPtr)));
    printf("Found at char %i\n", ((char*)vpPtr - caBuffer));
    return 0;
}

Output

memchr() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.