[Previous]
[Contents]
[Next]

memchr(), _fmemchr()

locate the first occurrence of a character in an object

Synopsis:

#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 );

Description:

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.

Returns:

A pointer to the located character, or NULL if the character doesn't occur in the object.

Examples:

#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

Classification:

memchr() is ANSI; _fmemchr() is WATCOM.
Safety:
Interrupt handler Yes
Signal handler Yes
Thread Yes

See also:

memcmp(), memcpy(), memicmp(), memset()


[Previous]
[Contents]
[Next]