| Functions | |||||||||||||||||||||||||||||||||||||||||
| Character manipulation | |||||||||||||||||||||||||||||||||||||||||
| Conversions to and from numeric formats | |||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||
| String manipulation | |||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||
| String examination | |||||||||||||||||||||||||||||||||||||||||
| Memory manipulation | |||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||
| Miscellaneous | |||||||||||||||||||||||||||||||||||||||||
(C11)(C11) | |||||||||||||||||||||||||||||||||||||||||
Defined in header <string.h> | ||
void* memchr(constvoid* ptr,int ch,size_t count); | (1) | |
/*QVoid*/*memchr(/*QVoid*/*ptr,int ch,size_t count); | (2) | (since C23) |
T be an unqualified object type (includingvoid).ptr is of typeconst T*, the return type isconstvoid*.ptr is of typeT*, the return type isvoid*.The behavior is undefined if access occurs beyond the end of the array searched. The behavior is undefined ifptr is a null pointer.
This function behaves as if it reads the bytes sequentially and stops as soon as a matching bytes is found: if the array pointed to byptr is smaller thancount, but the match is found within the array, the behavior is well-defined. | (since C11) |
Contents |
| ptr | - | pointer to the object to be examined |
| ch | - | bytes to search for |
| count | - | max number of bytes to examine |
Pointer to the location of the byte, or a null pointer if no such byte is found.
#include <stdio.h>#include <string.h> int main(void){constchar str[]="ABCDEFG";constint chars[]={'D','d'};for(size_t i=0; i<sizeof chars/(sizeof chars[0]);++i){constint c= chars[i];constchar*ps= memchr(str, c,strlen(str)); ps?printf("character '%c'(%i) found: %s\n", c, c, ps):printf("character '%c'(%i) not found\n", c, c);}return0;}
Possible output:
character 'D'(68) found: DEFGcharacter 'd'(100) not found
| finds the first occurrence of a character (function)[edit] | |
C++ documentation formemchr | |