Syntax
#include <string.h> /* also in <memory.h> */ void *memchr(const void *buf, int c, size_t count);Description
memchr searches the first count bytes of buf for the first occurrence of c converted to an unsigned char. The search continues until it finds c or examines count bytes.
memchr returns a pointer to the location of c in buf. It returns NULL if c is not within the first count bytes of buf.
This example finds the first occurrence of "x" in the string that you provide. If it is found, the string that starts with that character is printed.
#include <stdio.h> #include <string.h> int main(int argc,char **argv) { char *result; if (argc != 2) printf("Usage: %s string\n", argv[0]); else { if ((result = memchr(argv[1], 'x', strlen(argv[1]))) != NULL) printf("The string starting with x is %s\n", result); else printf("The letter x cannot be found in the string\n"); } return 0; /**************************************************************************** If the program is passed the argumrnt boxing, the output should be: The string starting with x is xing ****************************************************************************/ }Related Information