Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
Library Functions
 2012 Microchip Technology Inc.
DS52053B-page 345
Example
#include <string.h>
#include <stdio.h>
unsigned int ary[] = {1, 5, 0x6789, 0x23};
void 
main (void)
{
    char * cp;
    cp = memchr(ary, 0x89, sizeof ary);
    if(!cp)
        printf("Not found\n");
    else
        printf("Found at offset %u\n", cp - (char *)ary);
}
See Also
strchr()
Return Value
A pointer to the first byte matching the argument if one exists; NULL otherwise.
MEMCMP 
Synopsis
#include <string.h>
 
int memcmp (const void * s1, const void * s2, size_t n)
Description
The 
memcmp()
 function compares two blocks of memory, of length 
n
, and returns a 
signed value similar to strncmp(). Unlike strncmp() the comparison does not stop 
on a null character.
Example
#include <stdio.h>
#include <string.h>
void 
main (void)
{
    int buf[10], cow[10], i;
    buf[0] = 1;
    buf[2] = 4;
    cow[0] = 1;
    cow[2] = 5;
    buf[1] = 3;
    cow[1] = 3;
    i = memcmp(buf, cow, 3*sizeof(int));
    if(i < 0)
        printf("Less than\n");
    else if(i > 0)
        printf("Greater than\n");
    else
        printf("Equal\n");
}