Compartilhar via


memchr, wmemchr (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Finds characters in a buffer.

void *memchr(    const void*buf,    int c,    size_tcount);inline wchar_t *wmemset(   wchar_t*buf, 
   wchar_tc,
   size_tcount);

Parameters

  • buf
    Pointer to buffer.
  • c
    Character to look for.
  • count
    Number of characters to check.

Return Values

If successful, memchr returns a pointer to the first location of c in buf; otherwise, it returns NULL.

Remarks

The memchr function looks for the first occurrence of c in the first count bytes of buf. It stops when it finds c or when it has checked the first count bytes.

Example

/* MEMCHR.C */

#include <memory.h>
#include <stdio.h>

int  ch = 'r';
char str[] =    "lazy";
char string[] = "The quick brown dog jumps over the lazy fox";
char fmt1[] =   "         1         2         3         4         5";
char fmt2[] =   "12345678901234567890123456789012345678901234567890";

void main( void )
{
   char *pdest;
   int result;
   printf( "String to be searched:\n\t\t%s\n", string );
   printf( "\t\t%s\n\t\t%s\n\n", fmt1, fmt2 );

   printf( "Search char:\t%c\n", ch );
   pdest = memchr( string, ch, sizeof( string ) );
   result = pdest - string + 1;
   if( pdest != NULL )
      printf( "Result:\t\t%c found at position %d\n\n", ch, result );
   else
      printf( "Result:\t\t%c not found\n" );
}

Output

String to be searched:
      The quick brown dog jumps over the lazy fox
               1         2         3         4         5
      12345678901234567890123456789012345678901234567890

Search char:   r
Result:      r found at position 12

Requirements

OS Versions: Windows CE 2.0 and later.
Header: stdlib.h and wchar_ship.h.
Link Library: coredll.dll.

See Also

_memccpy | memcmp | memcpy | memset | strchr

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.