Path: utzoo!attcan!uunet!ibmps2!aix!bchristy From: bchristy@aix.aix.kingston.ibm.com (JB Christy) Newsgroups: comp.unix.aix Subject: Re: getopt (3) problem? Message-ID: <3452@aix.aix.kingston.ibm.com> Date: 12 Sep 90 15:30:24 GMT References: <1990Sep12.011152.26067@maverick.ksu.ksu.edu> Organization: Resource One, Inc. (Sub-contractor at IBM Kingston) Lines: 22 In article <1990Sep12.011152.26067@maverick.ksu.ksu.edu> proot@ksuvax1.cis.ksu.edu (Paul T. Root) writes: }In compiling and running some things, I have found that getopt doesn't act }right. When it runs out of parameters instead of returning an EOF it returns }a -1. }[...] }The work around I use is like this: } while(( c = getopt( argc, argv, "d:m" )), c != EOF && c != -1 ) { I was bitten by something similar, and I believe the problem is that EOF is #define'd as -1, which is an int, and I bet you've declared c as char. When the comparison occurs, c is promoted to an int but the sign is lost, so it becomes 255 instead of -1. Try casting EOF to a char, e.g. while(( c = getopt( argc, argv, "d:m" )) != (char) EOF ) { That way -1 gets "demoted" to a char and all is well. =-=-=-=-= Disclaimer: I don't even work for IBM; I certainly don't speak for them. -- JB (bchristy@aix, x0563, 5NC-01) Resource One, Inc. "She was a suicide blonde - dyed by (Sub-contractor at IBM Kingston) her own hand." --Rita Mae Brown