Name

memchr - scans memory for a character

Library

libc.lib

Synopsis

  #include <string.h>
  void * memchr (const void *b, int c, size_t len);

Return values

The memchr function returns a pointer to the byte located, or NULL if no such byte exists within len bytes.

Detailed description

The memchr function locates the first occurrence of c (converted to an unsigned char) in string b.

Examples

#include <string.h>
#include <stdio.h>
int main()
{
    char one[50];
    char* ret;
    strcpy(one,"abcd");
    ret = memchr("abcd", ’c’,4);
    if(!strncmp(one+2,ret,1)) printf("\ ’c\ ’ found in string \"abcd\"\n");
    ret = memchr(one, ’z’,4);
    if(ret == NULL) printf("\ ’z\ ’ not found in string \"abcd\"\n");           
    return 0;
}

         

Output

 ’c’ found in string "abcd"
 ’z’ not found in string "abcd"

         

See also

strchr, strcspn, strpbrk, strsep, strstr, strtok

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top