I'm trying to parse some arguments using getopt() like this:
char *fileName = "medit.db";
char c = ' ';
while((c = getopt(argc, argv, "f")) != -1){
switch(c){
case 'f':
fileName = optarg;
printf("%s\n\n", fileName);
break;
}
}
The thing is when I go to the command line and write
./server -f test
It just gives me a null result but if I write it like this
./server -ftest
All together it works just fine.
Any reason why this code wouldn't work like it intended?
EDIT: As an experiment I tried to put the colon like this f:
It works as intended.. Can anyone explain this?