Adding char to an int

I was wondering how it was possible to add a array to chars to an int as the function bellow does. Could someone explain this to me? And char *buf is an ARRAY of chars not just one. Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <sys/types.h>
#include <sys/socket.h>

int sendall(int s, char *buf, int *len)
{
    int total = 0;        // how many bytes we've sent
    int bytesleft = *len; // how many we have left to send
    int n;

    while(total < *len) {
        n = send(s, buf+total, bytesleft, 0);
        if (n == -1) { break; }
        total += n;
        bytesleft -= n;
    }

    *len = total; // return number actually sent here

    return n==-1?-1:0; // return -1 on failure, 0 on success
} 
buf is not a char; it is a pointer to a char. buf+total is adding an int to a pointer; this is called "pointer arithmetic" and is well worth reading up on.
Topic archived. No new replies allowed.