Question: how to do a lexicographic compare between two pointers with unknown byte size,
assuming both array size is equal,
eg implementing the following function to return -1 or 0 or 1 based on the comparecement and converting each byte to ascii

```
compare(const void *p1, const void *p2, int size)

```

EDIT: i added another argument with the size of bytes to compare, how can i cast each byte to char and compare between them ?

Answer: 
You're probably looking for the [`strcmp(3)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/strcmp.html) function.

**Update**

If your arrays are not of ASCII strings and may contain the `0x00` byte at any position without actually meaning anything, then you'll need the length as Oli points out, so you can use the [`memcmp(3)`](http://pubs.opengroup.org/onlinepubs/009695399/functions/memcmp.html) function:

```
int memcmp(const void *s1, const void *s2, size_t n);

```

**Update #2**

Okay, now that we've established you *also* want the byte that differs, you'll need your own function. Something like this (untested):

```
size_t cmp(const unsigned char *c1, const unsigned char *c2, ssize_t n) {
    ssize_t i;
    for (i=0; i<n; i++) {
        if (c1[i] != c2[i])
            return i;
    }
    -1;
}

```

This will let you find the byte values for whichever bytes differ. Note the `-1` return in case of no difference. This limits you to comparing objects whose size fit entirely in a `ssize_t`, which is smaller than the `size_t` type -- but since you're comparing two of them, I figure each one gets half the process address space at most anyway.
You need some way of knowing the size. Either explicitly (e.g. with a `size` argument or field in your data), or implicitly (e.g. with a null terminator).