| | |
getopt - help
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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 |
Tag cloud for C
#include adobe ansi array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic fflush file fork forloop framework getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware highest histogram inches include incrementoperators input iso kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix problem probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming stack standard string strings structures systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi






