Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

argv parsing

Status
Not open for further replies.

boebox

MIS
Oct 30, 2000
70
CA
I am writting a program that needs to parse argv as most programs do,
here is what I have:

while ((c = getopt(argc, argv, "q:")) != EOF) {
switch (c) {

case 'q':
qname = optarg;
break;
default:
usage(); /* Usage will exit */
}
}

Here is argv[]: ./a.out -q test sleep 100000

I then want to fork/exec sleep 10000, how do I get sleep 1000 into a char **? Right now I can only see sleep.

-Tony
 
i would think you need to have something like this

(This assumes sleep is followed by the value to sleep)

char* sleepCat;

...
// you currently know that argv == sleep and argv[i+1] == 10000

sleepCat = malloc(strlen(argv) + strlen(argv[i+1] +1);
sprintf(sleepCat,"%s %s",argv,argv[i+1]);

now use sleepCat to instead of the argv's

Matt
 
I will never learn that an "i" inside brackets [] means itallics, where argv is mentioned above assume argv[ i ]

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top