I have the following codeblock I’m using for German verb drills:
if (strcmp(*option, "sein") == 0)
*option = linie.sein;
if (strcmp(*option, "haben") == 0)
*option = linie.haben;
if (strcmp(*option, "possessiv") == 0)
*option = linie.possessiv;
if (strcmp(*option, "reflexiv") == 0)
*option = linie.reflexiv;
if (strcmp(*option, "accusativ") == 0)
*option = linie.accusativ;
if (strcmp(*option, "dativ") == 0)
*option = linie.dativ;
However I would like to condense it to something like:
*option = linie.(*option);
Or perhaps:
*option = linie.(*option)();
Unfortunately neither of these work. Any ideas?
Edit @dasblinkenlight:
typedef struct
{
char subjekt[20];
char sein[20];
char haben[20];
char possessiv[20];
char reflexiv[20];
char accusativ[20];
char dativ[20];
} satz;
satz linie =
{
.subjekt = "",
.sein = "",
.haben = "",
.possessiv = "",
.reflexiv = "",
.accusativ = "",
.dativ = ""
};
char *option = argv[1];
You are mixing compile-time and runtime options. In C, you can’t use an identifier directly from a string got at runtime. However, you can bring your comparaisons into an opaque function.