cancel
Showing results for 
Search instead for 
Did you mean: 

Help with getopt.h

SOLVED
Go to solution
Shannon Petry
Honored Contributor

Help with getopt.h

Been writing a program for a while, and seem to be having a bit of difficulty with usting the standard argument processor "getopt.h".

It works fine for regular arguments, but I can not seem to cast the string to an integer for a arg with option.

What is getopt.h returning in optarg?

case 'l':
password_length = (int)optarg ;
break;

simply returns junk, and no matter which type I have tried to cast fails...

Logic problem?

Thanks in advance!

Shannon
Microsoft. When do you want a virus today?
3 REPLIES
Vincent Stedema
Esteemed Contributor
Solution

Re: Help with getopt.h

Just a wild guess:

case 'l':
password_length = atoi(optarg) ;
break;

don't forget to include

HTH.

Regards,

Vincent
Shannon Petry
Honored Contributor

Re: Help with getopt.h

Darn good wild guess!

Where did you get that
atoi(optarg)
I'll asume it's an array?

I dug through man pages, and my C book...the C book was using strcat and strcopy to a buffer, and using the buffer... and strlen and such... yours was pretty easy!
Thanks!
Shannon
Microsoft. When do you want a virus today?
Kenneth Platz
Esteemed Contributor

Re: Help with getopt.h

Shannon,

Per the man page for getopt(2), "optarg" is defined as an "extern char *". So in order to convert this to an integer, you need to use the atoi() function from
I think, therefore I am... I think!