getopt_long() problems

K

Karthik

hi everyone,

I am using getopt_long() in one of my programs to parse out the
command line arguments.

The library call returns a character code of "1" which i am not sure
whether it is a errno or what it is.

The code snippet is :

---code---

static struct option const long_opts[] =
{
{"directory", no_argument, NULL, 'd'},
{"force", no_argument, NULL, 'f'},
{"interactive", no_argument, NULL, 'i'},
{"recursive", no_argument, NULL, 'r'},
{"verbose", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0}
};
.......
.......

int c = 0;

while ((c = getopt_long (argc, argv, "dfirvR", long_opts, NULL)) !=
EOF)
{
fprintf(stderr,"Value of c is : %d \n",c);

switch(c) {
.....

default:
fprintf(stderr,"I am here 1\n");
usage (1);

}
}

---code---


Output from the program: [partial ..coz rest is not needed in this
case]

---output---

Value of c is : 1
I am here 1

[usage text ]

---output---

Actually the usage text is being displayed multiple times ..say like
10 times or something. I am really confused and dont know what to do.
Any help is highly appreciated.

TIA

Karthik

ps: plz cc a reply to my email address also [k_mohanas AT yahoo DOT
com]
 
C

CBFalconer

Karthik said:
I am using getopt_long() in one of my programs to parse out the
command line arguments.
.... snip ...

ps: plz cc a reply to my email address also [k_mohanas AT yahoo
DOT com]

getopt is not a part of standard C. Maybe comp.unix.programmer?
And you should not expect direct e-mails, especially when you hide
your address. If the reply-to: field was set correctly you MIGHT
get the occasional direct reply, but in general the rule is "ask
here, read here".
 
K

Karthik

CBFalconer said:
Karthik said:
I am using getopt_long() in one of my programs to parse out the
command line arguments.

... snip ...
ps: plz cc a reply to my email address also [k_mohanas AT yahoo
DOT com]


getopt is not a part of standard C. Maybe comp.unix.programmer?
And you should not expect direct e-mails, especially when you hide
your address. If the reply-to: field was set correctly you MIGHT
get the occasional direct reply, but in general the rule is "ask
here, read here".

Thanx for the suggestion. This is my first post to a USENET group and i
was not sure how to go about doing everything. Now i kinda figured it
out. Will not request a direct reply next time.

Karthik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top