I am writing a simple code with readv. So find it read 1000 buffers of characters from a file with readv and end is print it but in this loop I am getting segFault
for (int i = 0; i < 1000; i++)
{
iov[i].iov_base = (char *)&buffers[i];
iov[i].iov_len = strlen(buffers[i]) + 1;
}
is there anything wrong with the pointers I am using. the pointer code is from this https://stackoverflow.com/a/69568527/4808760
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <string.h>
#include <sys/stat.h>
#define IP_FORMAT "*.*.*.*/*,*,*,*,*,*,*,*"
int main()
{
char *format=IP_FORMAT;
char (*buffers)[1001]=malloc(sizeof(char[2][1001]));
struct iovec iov[1000];
int fd=open ("./geoip2-ipv4_csv.csv",O_RDONLY);
for (int i = 0; i < 1000; i++)
{
iov[i].iov_base = (char *)&buffers[i];
iov[i].iov_len = strlen(buffers[i]) + 1;
}
int valread = readv (fd, iov, 1000);
for(int i=0;i<1000;i++)
{
printf ("%d: %s", i, (char *) iov[i].iov_base);
}
return 0;
}