How to use memchr() function in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

// void* memchr(const void* ptr, int ch, size_t count);

// finds the first occurrence of ch in a string

int main(void)
{
    char str[] = "c c++ ada java delphi";

    char* p = memchr(str, 'd', strlen(str));

    if (p != NULL)
        printf("Found: %s", p);
    else
        printf("Not found");

    return 0;
}




/*
run:

Found: da java delphi

*/

 



answered Apr 23, 2023 by avibootz
...