Using vars to access structures/functions
Jonathan
asst-jos at yetti.UUCP
Wed Jul 19 23:11:40 AEST 1989
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!!!
More information about the Comp.lang.c
mailing list