iovecs don't print right



Hi all,

Below is coded on linux. If you need specifics let me know. But the output
is all messed up.

//file revup.txt
Alpha centauri.
Centauri alpha.
pomato
//end revup.txt


#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <unistd.h>

int main ( )
{
char a[16], b[16], c[7];
struct iovec iov[3];
ssize_t nr;
int fd, i;
fd = open ("revup.txt", O_RDONLY);
if (fd == -1) {
perror ("open");
return 1;
}

/* set up our iovec structures */
iov[0].iov_base = a;
iov[0].iov_len = sizeof (a);
iov[1].iov_base = b;
iov[1].iov_len = sizeof (b);
iov[2].iov_base = c;
iov[2].iov_len = sizeof (c);

/* read into the structures with a single call */
nr = readv (fd, iov, 3);

if (nr == -1) {
perror ("readv");
return 1;
}
for (i = 0; i < 3; i++){
printf ("len %d, %d: %s \n", (int) iov[i].iov_len, i, (char *) \
iov[i].iov_base );
}
if (close (fd)) {
perror ("close");
return 1;
}

return 0;
}

//output with
$ gcc -Wall vectoredIORead.c -o vectoredIORead
$ ./vectoredIORead
len 16, 0: Alpha centauri.

len 16, 1: Centauri alpha.
Alpha centauri.

len 7, 2: pomato
//end of output

It is a bit weird since "Alpha centauri" is being printed twice and that too
in iov[1]!!?? What wrong am i doing here? :/

Appreciate your help.

--
thanks
.