Troubles with Multidimensional char* arrays... help needed.

Hi,

for a small project i have a char* array like that:

define MAX_Clients 12

char* Clients[MAX_Clients][3]={ {"192.168.17.1","Device 1",""}, {"192.168.17.2","Device 2",""}, {"192.168.17.5","Device 3",""}, {"192.168.17.6","Device 4",""}, {"192.168.17.10","Device 5",""}, {"","",""}, {"","",""}, {"","",""}, {"","",""}, {"xxx.xxx.xxx.xxx","Device 6","device6.dyndns.org"}, {"xxx.xxx.xxx.xxx","Device 7","device7.dyndns.org"}, {"xxx.xxx.xxx.xxx","Device 8","device8.dyndns.org"} };

its a multidimensional char array for strings.

the entries with the "xxx.xxx.xxx.xxx" are placeholders and resolved at runtime. but when i do something like

EntryNr = 9; //to set the IP of the first dynamic entry sprintf(Clients[EntryNr][0], "%d.%d.%d.%d\0", ResolvedIP[0], ResolvedIP[1], ResolvedIP[2], ResolvedIP[3]);

then not only the Entry for "Device 6" changed, but also the entries for the Device 7 & 8 too. i know, that this has something to do how the compiler handles the strings. because they are the same, they get the same memory. because when i use different placeholders, it works normal.

but, can anyone tell me how to handle such string arrays better?

thanks!

with best regards, martin

I think I would make a struct to hold the three bits of information and then have a single dimension left for the array.

Something like:

struct clientStruct {

     char ipAddress[16];
     char deviceName[MAX_DEVICE_NAME_SIZE];
     char whateverThatOtherFieldIs[ITS_MAX_SIZE];
};

clientStruct Clients[MAX_Clients];
char*  Clients[MAX_Clients][3]={
                       {"192.168.17.1","Device 1",""},               
                       {"192.168.17.2","Device 2",""},
                       {"192.168.17.5","Device 3",""},
                       {"192.168.17.6","Device 4",""},
                       {"192.168.17.10","Device 5",""},
                       {"","",""},

So, Clients[n][m] is a pointer. What is Clients[6][0] pointing to?

sprintf(Clients[EntryNr][0],  "%d.%d.%d.%d\0", ResolvedIP[0], ResolvedIP[1], ResolvedIP[2], ResolvedIP[3]);

Where, EXACTLY, are you storing the data?