I'm trying to use getopt in order to run two different functions depending on the arguments given.
int main(int argc, char **argv) {
int i;
int identify;
while ((identify = getopt(argc, argv, "c:")) != -1) {
switch (identify) {
case 'c':
for (i = 2; i < argc; i++) {
readerC(argv[i]);
}
default:
for (i = 2; i < argc; i++) {
reader(argv[i]);
}
}
}
return(0);
}
The purpose is that, if the command included "-c", then it would run the "readerC" function. If there were no arguments passed, then it would read the "reader" function.
I've revised the above function multiple times, but I can't seem to be able to run the "reader" function when running the command with no arguments (there is no output). Previously, putting in -c would run the readerC command as required, but after messing around with it, it now runs the readerC function followed by the reader function.
I tried changing "default:" to "case ':'" and "case '?'" but that hasn't worked either. Any help would be greatly appreciated :)