What do you mean "returning filenames"? The shell does the filename expansion. So your program will receive all of the filenames in the second parameter passed to main().
If you do ./myprog -i * and your main() definition looked like int main(int argc, char **argv) then argc would contain the count of all of the command-line arguments (plus the name of the command itself) and argv would contain a NULL-terminated list of strings representing those arguments.
argv would look something like:
argv[0] - "./myprog"
argv[1] - "1foo.001"
argv[2] - "1foo.1223"
.
.
.
argv[argc - 1] - "2foo.001"
argv[argc] - NULL
Is that what you're looking for?
Code:
itsme@itsme:~/C$ cat cline.c
#include <stdio.h>
int main(int argc, char **argv)
{
int i;
printf("argc = %d\n\n", argc);
for(i = 0;i < argc;++i)
printf("argv[%d] - %s\n", i, argv[i]);
return 0;
}
Code:
itsme@itsme:~/C$ ./cline foo bar blee
argc = 4
argv[0] - ./cline
argv[1] - foo
argv[2] - bar
argv[3] - blee
itsme@itsme:~/C$
And likewise:
Code:
itsme@itsme:~/C$ ls file[0-9].txt
file1.txt file2.txt file3.txt
itsme@itsme:~/C$ ./cline file[0-9].txt
argc = 4
argv[0] - ./cline
argv[1] - file1.txt
argv[2] - file2.txt
argv[3] - file3.txt
itsme@itsme:~/C$