Hey guys,

I'm working on a C++ program that runs/processes data from a bash shell on Cygwin. I've written code to parse command line arguments like so:

Qt Code:
  1. // in main(int argc, char *argv[])
  2. char testFile[10][256]; // holds up to 10 testFile names of up to 256 char each
  3. uint16 testFileNUM = 0;
  4.  
  5.  
  6. // call my parsing function:
  7. doArgs(argc, argv);
  8.  
  9.  
  10. // afterward report the parameter info
  11. for(uint16 a=0; a<testFileNUM; a++)
  12. printf("TestFile and NUM: %s %hd\n", testFile[a], testFileNUM);
  13.  
  14.  
  15. // snippet from command line parsing function
  16. void doArgs(int argc, char *argv[])
  17. {
  18. char *a;
  19. while(--argc > 0 && (*++argv)[0] == '-')
  20. {
  21. a = argv[0] + 1;
  22. switch(*a)
  23. {
  24. case 't':
  25. if(!strcasecmp(a, "test_file"))
  26. {
  27. sscanf(*++argv, "%s", &testFile[testFileNUM]);
  28. testFileNUM++;
  29. argc--;
  30. }
  31. else
  32. {
  33. printf("Unknown option: %s\n", *argv);
  34. usage();
  35. exit(1);
  36. }
  37. break;
  38. // etc...
  39. }
  40. }
  41. }
To copy to clipboard, switch view to plain text mode 

This has worked fine for me. If I type:

$> program -test_file text01.txt -test_file text02.txt -test_file text03.txt

I get the following expected report:

$> TestFile and NUM: text01.txt 3
$> TestFile and NUM: text02.txt 3
$> TestFile and NUM: text03.txt 3


This is what I want: after the file names have been read into the program, I can open them and do what I want.

However, now I've a situation such that, instead of specifying the input files specifically, I want to read them using a wildcard like so:

$> program -test_file text*.txt

But when I do so, I get the following report:

$> TestFile and NUM: text*.txt 1


This is useless to me (I think): I cannot keep track of and access the individual files. Can someone give me a suggestion here: how can I read the individual file names in my doArgs() function using the * wildcard?

Thanks!