Unix Programming - getopt_long() problem

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2004 > getopt_long() problem





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author getopt_long() problem
Karthik

2004-01-23, 5:36 pm

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]
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com