User manual

Table Of Contents
mikroC PRO for PIC32
MikroElektronika
621
memcmp
Prototype
int memcmp(void *s1, void *s2, int n);
Description Function compares the rst n characters of objects pointed to by s1 and s2 and returns zero if
the objects are equal, or returns a difference between the rst differing characters (in a left-to-right
evaluation). Accordingly, the result is greater than zero if the object pointed to by s1 is greater than the
object pointed to by s2 and vice versa.
Example
char txt[] = “mikroElektronika”;
char txt_sub[] = “mikro;
res = memcmp(txt, txt_sub, 16); // returns 69, which is ASCII code of the
rst differing character - letter ‘E’
memcpy
Prototype
void *memcpy(void *d1, void *s1, int n);
Description Function copies n characters from the object pointed to by s1 into the object pointed to by d1. If
copying takes place between objects that overlap, the behavior is undened. The function returns
address of the object pointed to by d1.
Example
char txt[] = “mikroElektronika”;
char txt_sub[] = “mikr;
res = memcpy(txt+4, txt_sub, 4); // string ‘txt’ will be populated with
the rst 4 characters of the ‘txt_sub’ string, beginning from the 4th
character
// routine returns the address of the rst
populated character, if memory areas of the strings don’t overlap
memmove
Prototype
void *memmove(void *to, void *from, int n);
Description Function copies n characters from the object pointed to by from into the object pointed to by to. Unlike
memcpy, the memory areas to and from may overlap. The function returns address of the object
pointed to by to.
Example
char txt[] = “mikroElektronika”;
char txt_sub[] = “mikr;
res = memmove(txt+7, txt_sub, 4); // string ‘txt’ will be populated with rst
4 characters of the ‘txt_sub’ string, beginning from the 7th character
// routine returns the address of the rst
populated character (memory areas of the object may overlap)