Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!ucsd!ucrmath!rearl From: rearl@watnxt3.ucr.edu (Robert Earl) Newsgroups: comp.unix.questions Subject: Re: how do I declare a constant as a variable of different type Message-ID: Date: 23 May 91 05:31:27 GMT References: <16452@helios.TAMU.EDU> Sender: news@ucrmath.ucr.edu Followup-To: comp.lang.c Organization: (EVIL!) Lines: 33 In-reply-to: n077gh@tamuts.tamu.edu's message of 23 May 91 03:16:32 GMT In article <16452@helios.TAMU.EDU> n077gh@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@watnxt3.ucr.edu \ --Sisters of Mercy rearl@gnu.ai.mit.edu /