- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- language and scripting
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2010 10:11 PM
тАО07-08-2010 10:11 PM
please forgive me if my question looks
very simple to you.
I am writing this
program in c
.....
while((c=getopt(..,..,..))!=-1)
{
...
...
......
}
but my two of my options in my program need more than two arguments
how do I do it please help.
Solved! Go to Solution.
- Tags:
- getopt/getopts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2010 12:54 AM
тАО07-09-2010 12:54 AM
Solution#include
#include
main (int argc, char *argv[])
{
int c;
int bflg, aflg=0, errflg=0;
extern char *optarg;
char *ifile,*ofile;
extern int optind, optopt;
while ((c = getopt(argc, argv, ":abf:o:")) != -1)
switch (c) {
case 'a':
aflg++;
break;
case 'f':
ifile = optarg++;
if (optarg[0]=='-')
errflg++;
else
{
ofile = ++optarg;
optind++;
}
break;
case ':': /* -f or -o without arguments */
fprintf(stderr, "Option -%c requires an argument\n",
optopt);
errflg++;
break;
case '?':
fprintf(stderr, "Unrecognized option: - %c\n",
optopt);
errflg++;
}
if (errflg) {
fprintf(stderr, "usage: . . . ");
exit (2);
}
printf("f= %s..%s..%d\n",ifile,ofile,aflg);
for ( ; optind < argc; optind++)
printf("%d %s\n",optind,argv[optind]);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2010 01:04 AM
тАО07-09-2010 01:04 AM
Re: language and scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2010 02:55 AM
тАО07-09-2010 02:55 AM
Re: language and scripting
your program is not taking two arguments
i takes first arguments properly but for the second one the program takes it as a string except the first two charecters of the first argument..
I want to mean that
if input is
./a.out -f 4567 7890
the output gets
f= 4567..67..0
so it does not taking the second argument
please help sir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2010 03:21 AM
тАО07-09-2010 03:21 AM
Re: language and scripting
case 'f':
ifile = optarg;
if (optarg[0]=='-')
errflg++;
else
{
ofile = argv[ optind++];
}
break;
sorry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2010 03:26 AM
тАО07-09-2010 03:26 AM
Re: language and scripting
sir
it helps me a lot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2010 03:41 AM
тАО07-09-2010 03:41 AM
Re: language and scripting
but our intervention is needed there
is there any way to avoid this
is there any function of technique is there
plese help me sir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2010 03:50 AM
тАО07-09-2010 03:50 AM
Re: language and scripting
I am not sure I understand what you are trying to do.
just an example could help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2010 03:55 AM
тАО07-09-2010 03:55 AM
Re: language and scripting
we write
while((c=getopt(...,...,":abc:")!=-1)
{
....
....
....
}
here the getopt can easily understand that the option c should need a argument with it
hence, it searchs for the argument when it sees the option -c in the string of one of it's strings stored in argv[] vector.
just like that do we have any other kind of option where the function it self searches for the two arguments or the argument list.
please help
sir
if u need any more clarification please reply me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2010 04:07 AM
тАО07-09-2010 04:07 AM
Re: language and scripting
./a.out -f toto tata -c arg1 arg2 arg3 arg4 ... -z
you want to get the list of -c args?