Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!mordor!sri-spam!sri-unix!hplabs!sdcrdcf!ism780c!jim From: jim@ism780c.UUCP (Jim Balter) Newsgroups: comp.sys.amiga Subject: Re: argv[n][n] doesn't exist Message-ID: <4801@ism780c.UUCP> Date: Sat, 6-Dec-86 18:29:24 EST Article-I.D.: ism780c.4801 Posted: Sat Dec 6 18:29:24 1986 Date-Received: Mon, 8-Dec-86 03:30:24 EST References: <816@ulowell.UUCP> Reply-To: jim@ism780c.UUCP (Jim Balter) Organization: Interactive Systems Corp., Santa Monica, CA Lines: 44 In article <816@ulowell.UUCP> walton@ametek.UUCP (Steve Walton) writes: >Bill Mayhew says (and others commiserate): >> I just ran into a minor annoyance with the Lattice C compiler >>that we have here at work. If memory stikes me right, it's version >>3.02. >> >>I discovered that when I read argv[n][n] that the string isn't always >>terminated with a \0 as you'd expect. This seems to happen mostly (if >>not only) when the string contains ascii characters that are digits. > >Ahem...argv is not a two dimensional array, but rather an array of pointers. >As such, it CANNOT be addressed with two subscripts as argv[n][n]. There >is a difference, see K&R for details. The correct way to find the \0 at >the end of the j'th argument is: > char *s; > s = argv[j]; > for (i = 0; s[i] != '\0'; i++); /* i is now length of arg j */ >If I badly misunderstood Bill's posting and have therefore insulted >everyone's intelligence, forgive me. > >Stephen Walton ARPA: ametek!walton@csvax.caltech.edu >Ametek Computer Research Div. BITNET: walton@caltech >610 N. Santa Anita Ave. UUCP: ...!ucbvax!sun!megatest!ametek!walton >Arcadia, CA 91006 USA >818-445-6811 You are wrong. You did not read or did not understand your C reference manual, and definitely did not test your claim before stating it as fact. Please act more resonsibly in the future and avoid insulting your *own* intelligence. Given the parameter or extern declarations (for definitions, "[]" is illegal, and a specific dimension must be given; for declarations, the innermost dimension can be left unspecified) "char **foo;" or "char *foo[];" or "char foo[][10];", even though these are represented in memory in three different ways (only two for parameters; "char **foo;" and "char *foo[];" are the same in that case, since an array cannot be passed on the stack, so foo must be a pointer and not a location) the references "foo[n][m]", "*(foo[n] + m)", and "*(*(foo + n) + m)" are all valid and all produce the same results. See K&R for details indeed. Do not trust in false wizards. -- -- Jim Balter ({sdcrdcf!ism780c,ima}!jim)