[H-GEN] 'C' code help needed
Martin Pool
mbp at pharos.com.au
Sun Oct 26 20:26:15 EST 1997
> Fun problem that particular piece was. Still I would strongly recommend
> that you forget about realloc for now, and just use a linked list to store
> the data as you read it, and then just copy it across to an array if
> necessary.
Or, perhaps better yet, use an array indexed by symbol or atomic number
with extant elements pointing to dynamically allocated information. Heck,
you could do both and index quickly by either key.
ElementInfo newEl = (ElementInfo *) malloc(sizeof(ElementInfo));
EL_BY_SYMBOL("He") = newEl;
arrelByNumber[2] = newEl;
arrelBySymbols is a 26x27 array indexed by the two letters of the
symbol, and you use a helper macro
#define EL_BY_SYMBOL(x) arrelBySymbol[x[0] - 'A'][x[1] ? (x[1] - 'a') : 0]
or some such. Usual disclaimers.
Of course, this is perhaps too complex for a little program, but
interesting.
Read 'data-driven programs' (?) in Code Complete.
--
Martin
----------------------- HUMBUG General List --------------------------------
echo "unsubscribe general" | mail majordomo at humbug.org.au # To Unsubscribe
More information about the General
mailing list