C library functions - memchr ()
C standard library - <string.h>
description
C library functionsvoid * memchr (const void * str , int c, size_t n) nbytes before the argumentstrpoints to the string of search (an unsigned character) the position of the first occurrence of characterc.
statement
Here is () statement memchr function.
void *memchr(const void *str, int c, size_t n)
parameter
- str - points to the memory block to perform a search.
- c - int values passed, but the function of each byte search using the form unsigned char values.
- n - thenumber of bytes to be analyzed.
return value
This function returns a pointer to a pointer to the matching byte, if the character does not appear in a given area of memory, it returns NULL.
Examples
The following example demonstrates memchr () function is used.
#include <stdio.h> #include <string.h> int main () { const char str[] = "http://www.w3cschool.cc"; const char ch = '.'; char *ret; ret = memchr(str, ch, strlen(str)); printf("|%c| 之后的字符串是 - |%s|\n", ch, ret); return(0); }
Let's compile and run the above program, which will result in the following:
|.| 之后的字符串是 - |.w3cschool.cc|