C Standard Libraries C++

strchr()

Declaration

char* strchr(const char* kcpString, int iChar);

Description

This function returns a pointer to the first instance of "iChar" in the null-terminated string "kcpString." If the function fails to find an instance of "iChar," it returns NULL.

Example

#include <cstdio>
#include <cstring>

int main()
{
    char caString[] = "XoaX.net";

    char* cpFound = strchr(caString, 'n');
    printf("Found character: %c\n", *cpFound);
    printf("Found at char %i\n", (cpFound - caString));

    return 0;
}

Output

strchr() Output
 

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