memchr, _fmemchr
raw OCR
Searches n bytes for character c.
Defined in header <mem.h>
Syntax
#include <mem.h>
Near version: void *memchr (const void *s, int c, size_t n);
Far version: void far * far _fmemchr(const void far *s, int c, size_t n);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only | |
|---|---|---|---|---|---|
| Near version | ■ | ■ | ■ | ■ | |
| Far version | ■ | ■ |
Remarks
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.
Example
include <string.h>
#include <stdio.h>
int main (void)
{
char str[17], *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;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Extraction notes
- heading `memchr, _fmennchr` read as `memchr, _fmemchr`
Stable link: /3.1/mem.h/memchr/
· short form /3.1/memchr/