The memchr () function in C
The function void * memchr (const void * str, int c, size_t n) looks for the first occurrence of the character c (an unsigned char) in the first n bytes of the string pointed to by parameter str.
The function void * memchr (const void * str, int c, size_t n) looks for the first occurrence of the character c (an unsigned char) in the first n bytes of the string pointed to by parameter str.
Declaring the function memchr () in C
Below is the declaration for memchr () in C:
void * memchr ( const void * str , int c , size_t n )
Parameters
str - This is the pointer to the memory block where the search is performed.
c - This is the value to be transmitted in the form of an int, but the function performs a byte search using the unsigned char conversion of this value.
n - This is the number of bytes to be analyzed.
Returns the value
This function returns a pointer to the connected byte or NULL if the character does not appear in the given memory area.
For example
The following program C illustrates the usage of memchr () in C:
#include #include int main () { char * pch ; char str [] = "Hoc C co ban va nang cao tai QTM" ; pch = ( char *) memchr ( str , 'v' , strlen ( str )); if ( pch != NULL ) printf ( "Tim thay 'v' tai vi tri %d.n" , pch - str + 1 ); else printf ( "Khong tim thay ky tu 'v'.n" ); return 0 ; }
Compiling and running the above C program will result:
According to Tutorialspoint
Last lesson: string.h in C
Next lesson: Function memcmp () in C
You should read it
- The function atoi () in C
- The getchar () function in C
- Call the function by value in C ++
- The atol () function in C
- The function strtod () in C
- Putchar () function in C
- Call the function by pointer in C ++
- The abort () function in C
- Function in programming C
- The rewind () function in C
- The ord () function in Python
- Int () function in Python
Maybe you are interested
NASA announced its plan to search for extraterrestrial life Discovered mysterious signals emanating from a star right next to the Solar System, possibly of aliens NASA reveals its latest snapshot of the Martian surface with a resolution of 1.8 billion pixels Found the second planet of Proxima Centauri, the star closest to the sun The most remote and least-populated places on Earth 7 most modern astronaut ships on the planet