| | |
getopt - help
![]() |
•
•
Join Date: Sep 2008
Posts: 3
Reputation:
Solved Threads: 1
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..
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..

C Syntax (Toggle Plain Text)
#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; }
As far as I know you need "t:" getopt option. May be I'm wrong (I don't like getopt
).
See http://www.gnu.org/software/libtool/...l#Using-Getopt
).See http://www.gnu.org/software/libtool/...l#Using-Getopt
•
•
•
•
filetype = ????;
c Syntax (Toggle Plain Text)
filetype = optarg;
ssharish
"Any fool can know, point is to understand"
![]() |
Similar Threads
- 'import' wrinkles (Python)
- Mail command (Shell Scripting)
- Help with getopt/getopts (Shell Scripting)
- shell script as a daemon (Shell Scripting)
- freevo uses python (Python)
- Doubts about constructor (C++)
- Help with UNIX more c code (C)
- php error when using invision board (PHP)
- Can you add pictures/sounds in a win32 console app? (C)
Other Threads in the C Forum
- Previous Thread: Frames in C ...
- Next Thread: Real COM port vs. USB-to-Serial cable
| Thread Tools | Search this Thread |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators intmain() iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling segmentationfault send shape socketprograming socketprogramming stack standard strchr string suggestions systemcall test unix urboc user variable voidmain() wab win32api windows.h






