writing a getopt() like function

  • Thread starter Bill Cunningham
  • Start date
B

Bill Cunningham

I have just learned that what I have been wanting to do at the command
line can be acomplished with getop(). A posix function. Now I was looking
for a C89 approach to this. When working with linux I might be able to use
getop but when using djgpp and windows I can't. Can C89 help me here.

Bill
 
L

Lew Pitcher

I have just learned that what I have been wanting to do at the command
line can be acomplished with getop(). A posix function. Now I was looking
for a C89 approach to this. When working with linux I might be able to use
getop but when using djgpp and windows I can't.

Yes, you can. All you need is the source for getopt, which is available from
the Free Software Foundation (GNU)
Can C89 help me here.

Only in that getopt can be written in C89 (or C99, for that matter). There
is no getopt-like function in the C89 standard library.

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
L

Lew Pitcher

I have just learned that what I have been wanting to do at the command
line can be acomplished with getop(). A posix function. Now I was looking
for a C89 approach to this. When working with linux I might be able to use
getop but when using djgpp

I just checked - take a look at the Delorie.com documentation for libc:
http://www.delorie.com/djgpp/doc/libc/libc_406.html

and windows I can't. Can C89 help me here.

Bill

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
B

Bill Cunningham

[snip]
Only in that getopt can be written in C89 (or C99, for that matter). There
is no getopt-like function in the C89 standard library.
OK Lew do you think I can handle it? Writing a getop like function in c89 ?
I'm thinking argv[1][0] or argv [2][0] here for example.

Bill
 
L

Lew Pitcher

[snip]
Only in that getopt can be written in C89 (or C99, for that matter).
There is no getopt-like function in the C89 standard library.
OK Lew do you think I can handle it? Writing a getop like function in c89
? I'm thinking argv[1][0] or argv [2][0] here for example.

I'd much rather suggest that you download and use the source code for getopt
from gnu.org (say, from
ftp://mirrors.kernel.org/gnu/gengetopt/gengetopt-2.22.tar.gz) or use the
getopt that apparently comes with djgpp.

Please don't take this wrong, but I don't think that you are quite yet up to
writing your own getopt substitute.

HTH
--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
B

Barry Schwarz

[snip]
Only in that getopt can be written in C89 (or C99, for that matter). There
is no getopt-like function in the C89 standard library.
OK Lew do you think I can handle it? Writing a getop like function in c89 ?
I'm thinking argv[1][0] or argv [2][0] here for example.

What exactly did you intend the last statement to mean.
 
B

Barry Schwarz

I have just learned that what I have been wanting to do at the command
line can be acomplished with getop(). A posix function. Now I was looking

None of the code you have recently posted seems like a candidate for
this. Do you really have a clear idea of what you want to accomplish?
 
B

Bill Cunningham

What exactly did you intend the last statement to mean.
I am thinking that with char** when looking for something like -d or -a
you'll want to check the first element of the argvs.

Bill
 
B

Bill Cunningham

It's best to stick to ANSI C for jobs which can be done in ANSI C. Then
the program will always work on any computer.

Exactly. That's why I inquired about about writing in C89 a getopt()
like function.

Bill
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top