locate the first occurrence of a character in an object
#include <string.h> void *memchr( const void *buf, int ch, size_t length ); void __far *_fmemchr( const void __far *buf, int ch, size_t length );
The memchr() function locates the first occurrence of ch (converted to an unsigned char) in the first length characters of the object pointed to by buf.
The _fmemchr() function is a data-model-independent form of the memchr() function. It accepts far pointer arguments, and returns a far pointer. It is most useful in mixed memory model applications.
A pointer to the located character, or NULL if the character doesn't occur in the object.
#include <stdio.h> #include <string.h> void main() { char buffer[80]; char *where; strcpy( buffer, "video x-rays" ); where = (char *) memchr( buffer, 'x', 6 ); if( where == NULL ) printf( "'x' not found\n" ); else printf( "%s\n", where ); where = (char *) memchr( buffer, 'r', 9 ); if( where == NULL ) printf( "'r' not found\n" ); else printf( "%s\n", where ); }
produces the output:
'x' not found rays
Safety: | |
---|---|
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |
memcmp(), memcpy(), memicmp(), memset()