7fa Subj : how to initialize this? To : borland.public.cpp.borlandcpp From : Eric Date : Wed Oct 15 2003 09:58 am Hi, I want to simplify this so later if i add a field it deosnt all have to be re-written. Here's what i want: typedef struct { char *Name; int Value; }TAnimal; TAnimal Farm0[] = {{"dog", 0}, {"horse", 4}, {"cow", 6}}; TAnimal Farm1[] = {{"dog", 0}, {"horse", 4}, {"cow", 6}}; TAnimal Farm2[] = {{"dog", 0}, {"horse", 4}, {"cow", 6}}; TAnimal Farm3[] = {{"dog", 0}, {"horse", 4}, {"cow", 6}}; Each array is the same, in the real world i would use them for repetitive items. The trouble i have now is that if i want to add say {"cat", 0} i have to insert it in each array. How do i declare an intiailzed type so that it is something like this: typedef struct { char *Name; int Value; }TAnimal; typedef TAnimal TFarm[] = {{"dog", 0}, {"horse", 4}, {"cow", 6}}; TFarms Farms[4]; so suppose my input is [Farm-01] Pig = 12 Cow = 57 Horse=3 And now (if i can find a way to do such a thing) FarmNum = get number from [Farm-01] == 1 Next iterate through the possible animals if Farms[FarmNum].Name[1] == "horse" // found a horse so record its value Farms[FarmNum].Value[1] = 4 And to add a new animal i would simply do this (at compile time of course) typedef TAnimal TFarm[] = {{"dog", 0}, {"horse", 4}, {"cow", 6}, {"pig", 22}}; I hope i am explaining what I'm after clearly enough. I need to iterate through this list taken from an input file and for each [Farm-00] Pig = 2 Cow = 5 [Farm-01] Pig = 12 Cow = 57 When i see a [] header i extract the Farm number and use it to index my Farms array, since all Farms array have the same elements but may have different integer values for the various animals I can do this in a nice neat loop, Adding Farms means no real extra code, adding animals also means the parser that gets the values for the animals doesnt change. Thanks Eric . 0