Hi, I have doubt on using structure array for my project. My project have some scenarios, example, 4 nodes and one wireless access point. Each node have different parameters like IP Address, node ID, name,status,etc. Also the wireless access point have SSID, name, IP Address, type. Initialy I thought top using struct array so that each array element represent one node and it have store the parameters, some thing like follows, typedef struct NODE { char *IPADDR, int nodeID, char *name, bool status }node; typedef struct WIRELESSAP { char *IPADDR, int nodeID, char *name, bool status, char *SSID, char *type }wap; For my above requirement, I need 4 node structures to store the corresponding values. So, i create struct array like this, Code: node nodearr[4]; [\code] I read one configuration file and using strtok() function, I read each node different parameters and store in node array. But, when I try to print the values, It shows some last node value only in each array element of node struct. Is it correct to use structure array for my purpose?. Is it possible to use linked list for my requirement?. I think don't use linked list, because I read config file, and the file doesnot contain each node in sequensely. My configuration file contains as follows, [configfile] NODE-1 IPADDR 192.168.12.1 NODE-1 NODEID 1 NODE-2 IPADDR 192.168.12.2 NODE-1 NAME node1 NODE-1 STATUS ON NODE-2 NAME node2 NODE-2 NODEID 2 NODE-3 IPADDR 192.168.12.3 NODE-4 IPADDR 192.168.12.4 NODE-2 STATUS ON NODE-3 NODEID 3 NODE-4 NODEID 4 NODE-3 NAME node3 NODE-3 STATUS ON NODE-4 NODEID 4 NODE-4 NAME node4 NODE-4 STATUS OFF [/configfile] Using delimiter as "- {} ". I want to store first node values in nodearr[0] like that. So, what is best approach to read the config file and store the values in corresponding node structures. If linked list possible, how can I use it.
Hi ram.sj,You can very well assign the values from a config file to a structure. Probably there is some error in the way you are assigning it or maybe you are overwriting the values already written in the array. Kindly check your code or share it so that i can find out the problem.Please specify why u are using {} as delimiter?
ok so first of all your decision of taking structures is not bad.why unnecessarily increase the complexity of program by using linked lists...? The major cause of your problem is this code in your structs Code: char *IPADDR; char *name; char *SSID, char *type you must replace this with arrays Code: char IPADDR[20]; char name[10]; char SSID[20]; char type[15]; The reason requires little depth on strings in c. let me explain in brief may be in your approach each node is not getting its own space for strings .instead all the nodes are pointing to the same string literal. at the end just understand that there is a whole lot of difference between array strings and string literals and most of us assume that they are the same.... I suggest you to take a dive in the topic. If you are encountering problems you can post it here.i have the working code ready with me.... have fun...