Manual

Neuron C Reference Guide 109
Example
#include <mem.h>
unsigned array1[40];
void f(void)
{
// Copy up to 40 bytes to array1,
// but stop if an ASCII “W” value is copied.
unsigned *p;
p = memccpy(array1, “Hello World”, ‘W’, sizeof(array1));
}
When the function returns,
array1
contains “Hello W”, but no terminating ‘\0’
character, and
p
points to the 8th byte in the
array1
array (following the ‘W’).
memchr( ) Function
The memchr( ) function searches the first
len
bytes of the memory area pointed to
by
buf
for the first occurrence of character
c
, if it exists. The function returns a
pointer to the byte in
buf
containing
c
, else memchr( ) returns NULL. See also
ansi_memcpy( ), ansi_memset( ), eeprom_memcpy( ), memccpy( ), memcmp( ),
memcpy( ), and memset( ).
Syntax
#include <mem.h>
void *memchr (const void *
buf
, int
c
, unsigned long
len
);
Example
#include <mem.h>
unsigned array[40];
void f(void)
{
unsigned *p;
// Find the first 0xFF byte, if it exists
p = memchr(array, 0xFF, sizeof(array));
}
memcmp( ) Function
The memcmp( ) function compares the first
len
bytes of the memory area pointed
to by
buf1
to the memory area pointed to by
buf2
. The function returns 0 if the
memory areas match exactly. Otherwise, on the first non-matching byte, the
byte from each buffer is compared using an unsigned comparison. If the byte
from
buf1
is larger, then a positive number is returned, else a negative number is
returned. See also ansi_memcpy( ), ansi_memset( ), eeprom_memcpy( ),
memccpy( ), memchr( ), memcpy( ), and memset( ).