Hi like to write a program that can take arguments like %program -t <type> <path> <path> <name>
where -t follow by type is the file type I like to look for in a find program, and path's is where I want to look, followed by the name of the file I like to search for....
like
%program -t f (file) ~testfolder1 ~testfolder2 help
The problem is I don't know how to get getopt to read -t and then take next char as an argument to look for S_ISREG(m) for example..
Would be great with a lite help, will try to update the thread later on with code if someone have same problem.. :)
#include <stdio.h>
#include <unistd.h>
int main (int argc, char *argv[]){
int c;
char *path, filetype;
extern char *optarg;
extern int optind, optopt, opterr;
while ((c = getopt(argc, argv, "t")) != -1){
switch(c){
case 't':
filetype = ????; // What the *** should be here? :D
printf("Type you are looking for is:
%c\n", filetype);
printf("option: %c\n",c);
break;
case '?':
fprintf(stderr, "Unrecognised option:
-%c\n",optopt);
}
}
// This is just for listing witch arguments there is..
for(i=1;i<argc;i++){
printf("argv: %s\n",argv[i]);
}
return 0;
}