Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-sdd!ncr-sd!se-sd!rns From: rns@se-sd.sandiego.ncr.com (Rick Schubert) Newsgroups: comp.lang.c Subject: Re: programming challenge (silly) Message-ID: <1875@se-sd.sandiego.ncr.com> Date: 29 Mar 89 16:12:45 GMT References: <37433@think.UUCP> <4412@ingr.com> <1859@se-sd.sandiego.ncr.com> <12145@haddock.ima.isc.com> <1866@se-sd.sandiego.ncr.com> <2417@buengc.BU.EDU> Reply-To: rns@se-sd.sandiego.NCR.COM (Rick Schubert(AEP)) Organization: NCR Corp. Systems Engineering, San Diego Lines: 42 In article <2417@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes: >In article <1866@se-sd.sandiego.ncr.com> rns@se-sd.sandiego.NCR.COM (Rick Schubert(AEP)) writes: >>I believe that >> argc == 0 && argv[0] == NULL >>is intended for the case where the implementation has no access to >>the command line (or there is no command line), whereas >> argc > 0 && argv[0] == "" >>is intended for the case where the implementation has access to the command >>line but not to the program name. >I get it. One is a null pointer, and the other is a pointer-to-a-null... > --Blair In the interest of trying to keep my postings brief and to the point, I may, at times, assume too much and leave out something that maybe should have been said. When I wrote: >> argc > 0 && argv[0] == "" >>is intended for the case where the implementation has access to the command >>line but not to the program name. I meant to imply that not only argc > 0 but that, potentially argc > 1 That is, since the implementation has access to the command line but not to the program name, the program may be invoked with arguments, which are pointed to by argv[1], argv[2], ..., argv[argc-1]. As always, argv[argc] == NULL so that, if argc == 0, argv[0] == NULL Also, argv[i] (for 0 <= i < argc) points to a C string (i.e. is not NULL), so that, if argc > 0, argv[0] cannot be NULL and must point to a string. If the program name is not available, "" is probably the most reasonable choice. I hope this posting strikes a good balance between conciseness and verbosity. Also, I hope that my mixing of C expressions and C/English is not too confusing (I can't post in multiple fonts). -- Rick Schubert (rns@se-sd.sandiego.NCR.COM)