how do I declare a constant as a variable of different type
Robert Earl
rearl at watnxt3.ucr.edu
Thu May 23 15:31:27 AEST 1991
In article <16452 at helios.TAMU.EDU> n077gh at tamuts.tamu.edu (Sharma Anupindi) writes:
| I read a string ( which is unknown prior to readig ) into character variable.
| like:
| char name[30];
| fsacnf(fp,"%s",name);
| Now I want to declare the string I have read from the file as a different variable.
For the most part, You Can't Do That in C. The best you can do is
create an array of structs, such as:
#define NUMVARS 50
struct {
char *nam; /* or char nam[80]; */
int val;
} variables[NUMVARS]; /* or make it a linked list if it grows */
And then read stuff in, putting the names into the variables[n].nam
members and putting values in the variables[n].val integers, then look
them up by just searching the array, or creating a hash table system
to look them up directly. There's no way to create a new symbol after
C has been compiled; besides, this method is a lot like the way LISP
interns symbols and associates them with values in the first place.
:-)
--
______________________________________________________________________
\
robert earl / "Love is a many splintered thing"
rearl at watnxt3.ucr.edu \ --Sisters of Mercy
rearl at gnu.ai.mit.edu /
More information about the Comp.unix.questions
mailing list