Subject: Re: Can I use getopt in a simple program with cygwin32 ?
From: [email-masked] (Aram Nahidipour)

11 Feb 1998 15:07:51 -0800
Message-ID: <[email-masked]>
To: [email-masked], [email-masked]

Cormac,

Please be more specific what version and why don't you include you c code
also.  I tried the following code and it is working fine. my version
is cygwin32-b18.
------------------------ C code ----------------------------
#include <stdio.h>
#include <strings.h>

main(int argc, char *argv[])
{
	extern char    *optarg;
	int             c;

	int             inttemp;
	int             fd;
	char            chartmp[256];
	int             i;
	char           *datafile = "aram.test";

	while ((c = getopt(argc, argv, "dhf:")) != -1)
		switch (c) {
		case 'f':
			datafile = strdup(optarg);
			break;
		case 'h':
			printf("\"%s\" Usage:\n", argv[0]);
			printf("\t-f 	<data buffer to be created>\n");
			printf("\t-d 	dump the content of the data file\n");
			exit(0);
		default:
			break;

		}

	return 0;
}
------------------------------------------------------------------

Regards,
Aram
> 
> Hi,
> 
> I have a simple program that is command line driven and calls getopt
> within the program, however when i compile it using "gcc file.c" I get
> file.c: in function 'main':
> file.c:47: 'optarg' undeclared (first use this function)
> file.c:47: (Each undeclared identifier is reported only once
> file.c:47: for each function it appears in.)
> file.c:91: 'optopt' undeclared (first use this function)
> 
> What is going on? The same source code compiles under Linux and HP-UX no 
> problem... can I not use the optopt and optarg and optind variables that
> i would expect the calling of the function getopt to set ???
> 
> Please e-mail me a reply, as I do not subscribe to the mailing list, but
> searched through the archives for an answer.....
> 
> Thanks in advance
> Cormac
> --
> -------------------------------------------------------------------------------
> Cormac McGuinness                       e-mail: [email-masked]
>                                                 [email-masked]
> ===============================================================================
> Experimental Physics Department,        Tel:    + 353 1 706 2205
> University College Dublin,              Fax:    + 353 1 283 7275
> Belfield, Dublin 4, Ireland.            
>         Also:
> School of Physical Sciences,            Tel:    + 353 1 704 5840
> Dublin City University,                 Fax:    + 353 1 704 5384
> Glasnevin, Dublin 9, Ireland
> 
> 
> -
> For help on using this list (especially unsubscribing), send a message to
> "[email-masked]" with one line of text: "help".
> 
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".