Obligatory total noob here.
I am making a simple C program that reads some variables from a file from a simple function. What I'm trying to accomplish, however, is to allow whoever calls the program to override the values read from the file if hey so specify in the command line arguments. I would like to have something like this:
char* filename;
int number;
...
readConfig(filename, number, ...);
if (argc > 1) {
// Check if the variables were in the args here, in some way
strcpy(filename, args[??]);
number = atoi(args[??]);
}
I would like the program to be called as
program -filename="path/to/file.txt" -number=3
I figured out I could just tokenize each argument and match it to every assignable variable and discard the others, but I'm pretty sure that there's a more elegant way to do this (perhaps with getopts?)
Thank you so much for your help.