This is driving me a little crazy
I have a struct
typedef struct{
char url [1000];
char ip [16];
}DnsEntry;
I want to create a dynamic array of these and populate them
like
It compiles, but the array is not creating correctly. I have googled this, and not found anything that works for me. What I need to understand it how to
dynamically size the array,
put DnsEntry records into the array
add more DnsEntry records into the array.
Could someone post some code or a link to where I should be looking?
Thanks
Charlie Benger-Stevenson
Hart Hill IT Ltd
I have a struct
typedef struct{
char url [1000];
char ip [16];
}DnsEntry;
I want to create a dynamic array of these and populate them
like
Code:
dnscache = (DnsEntry*) malloc(sizeof(DnsEntry) * 2);
char *url="[URL unfurl="true"]www.yahoo.com";[/URL]
char *ip="87.248.113.14";
memset(dnscache[0].url,0x0,sizeof(dnscache[0].url));
strcpy(dnscache[0].url,url);
memset(dnscache[0].ip,0x0,sizeof(dnscache[0].ip));
strcpy(dnscache[0].ip,ip);
url="[URL unfurl="true"]www.bbc.co.uk";[/URL]
ip="212.58.253.67";
dnscache[1] = (struct DnsEntry *)malloc(sizeof(DnsEntry));
memset(dnscache[1].url,0x0,sizeof(dnscache[1].url));
strcpy(dnscache[1].url,url);
memset(dnscache[1].ip,0x0,sizeof(dnscache[1].ip));
strcpy(dnscache[1].ip,ip);
It compiles, but the array is not creating correctly. I have googled this, and not found anything that works for me. What I need to understand it how to
dynamically size the array,
put DnsEntry records into the array
add more DnsEntry records into the array.
Could someone post some code or a link to where I should be looking?
Thanks
Charlie Benger-Stevenson
Hart Hill IT Ltd