memchr, wmemchr

From RAD Studio
Jump to: navigation, search

Go Up to mem.h Index


Header File

mem.h, string.h

Category

Memory and String Manipulation Routines, Inline Routines, C++ Prototyped Routines

Prototype

void *memchr(const void s, int c, size_t n);/ C only */

const void *memchr(const void *s, int c, size_t n);// C++ only

void *memchr(void *s, int c, size_t n);// C++ only

void *memchr(const void s, int c, size_t n);/ C and C++ */

void * _wmemchr(void s, int c, size_t n);/ unicode version */

Description

Searches n bytes for character c.

memchr is available on UNIX System V systems.

memchr searches the first n bytes of the block pointed to by s for character c.

Return Value

On success, memchr returns a pointer to the first occurrence of c in s; otherwise, it returns NULL.

Note: If you are using the intrinsic version of these functions, the case of n = 0 will return NULL.

Example

#include <string.h>
#include <stdio.h>
int main(void)
{
    char str[17];
    char *ptr;
    strcpy(str, "This is a string");
    ptr = (char *) memchr(str, 'r', strlen(str));
    if (ptr)
       printf("The character 'r' is at position: %d\n", ptr - str);
    else
       printf("The character was not found\n");
    return 0;
}
 

Portability

POSIX Win32 ANSI C ANSI C++

memchr

+

+

+

+

_wmemchr

+