Path: utzoo!yunexus!yetti!asst-jos From: asst-jos@yetti.UUCP (Jonathan) Newsgroups: comp.lang.c Subject: Using vars to access structures/functions Message-ID: <329@yetti.UUCP> Date: 19 Jul 89 13:11:40 GMT Article-I.D.: yetti.329 Reply-To: asst-jos@yetti.UUCP (Jeffrey Klein) Organization: York U. Computer Science Lines: 28 Is it possible to place the name of a field in a variable, and then use that variable to reference the field? For a contrived example, if I have a structure that has a large number of fields, and I want to reference a field, by querying the user for the field name rather than do the following: getfieldname(var); if ( strcmp(var, "fieldname1") == 0) do whatever to field1 else if (strcmp( var, "fieldname2) == 0) do whatever to field2 else .... In effect, this is to come up with a general solution to the problem rather than re-write the code for each situation like this that arises. This would apply to pointers to functions as well. Is it possible to use the name of a function (read in from the terminal, for example) to execute the function (assuming that it exists) without creating a cross reference table first? I have tried this and have been unable to do this. This does not seem possible, but you never know!!! Any and all help (flames included :-) ) accepted. e-mail is welcome. ------------------------------------------------------------------------- Jeffrey Klein York University, Toronto UUCP: Uunet!utai!utcsri!yunexus!yuyetti!asst-jos Standard Disclaimer: This is MY opinion, not York University's!!!