Newsgroups: comp.unix.questions Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!ispd-newsserver!garden.ssd.kodak.com!weimer From: weimer@garden.ssd.kodak.com (Gary Weimer (253-7796)) Subject: Re: how do I declare a constant as a variable of different type Message-ID: <1991May23.173101.8638@ssd.kodak.com> Sender: news@ssd.kodak.com Reply-To: weimer@ssd.kodak.com Organization: Eastman Kodak Co.; Rochester, NY References: <16452@helios.TAMU.EDU> <1991May23.145852.13033@fmi.uunet.uu.net> Date: Thu, 23 May 91 17:31:01 GMT [I messed up who said what...but it is shorter :-)] > I read a string ( which is unknown prior to readig ) into character variable. >: >name[30]; >(fp,"%s",name); >I want to declare the string I have read from the file as a different variable. >Ex: > If my file contains the string "Mr.Brilliant", then name will contain the same >string. >Now I want to declare "Mr.Brilliant" as a integer, for further use in the program. >And I wanted to know how to do that. To clarify what I think you are trying to say, here is a csh example: set name="MrBrilliant" #read "Mr.Brilliant" set $name=5 #delare "Mr.Brilliant" integer echo "$MrBrilliant = 5" #prints "5 = 5" The answer is: you can't do this in C (you CAN simulate if you try hard enough). What you are trying to do is take DATA (the string "Mr.Brilliant") and declare it as a VARIABLE (int in this case). A variable points to a memory location; data is what is stored at that location. This is not something you should be trying to do anyway. It implies that somewhere in your code you are going to say something like: printf("Mr.Brilliant = %d", Mr.Brilliant); If your data file changes (let's say Mr.Brilliant changes to Mr.Brillo), this printf will now have an undeclared variable. If you could describe what you are really trying to acomplish, we might be able to tell you the "C" way to do handle it. I am quite sure that the "proper" way to do it will be a lot easier than trying to simulate what you are trying to do. weimer@ssd.kodak.com ( Gary Weimer )