🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.c.moderated
2 messages
2 total messages Started by boerkees Sat, 16 Mar 1996 16:23
Re: Coding problem
#2305
Author: boerkees
Date: Sat, 16 Mar 1996 16:23
58 lines
2383 bytes
> From: proctor@corp.hp.com (Stephen Proctor)
> Subject: C coding problem
> Date: 14 Mar 1996 21:14:55 -0600
> Greetings,
> 
[snip]
> #include <stdio.h>
> #include <ctype.h>
> #include <string.h>
> #include <stdlib.h>
> 
> main(int argc, char *argv[])
> {
> int ii;
> int option_val = 0;
> /* skip lines */
> for (ii=1; ii<argc; ii++) {
> /* skip lines */
> /* The next line is the offending line */
>    if (*argv[ii] == '-') option_val = read_options;
> /* skip lines */
> return 0;         /* Program executed successfully */
> }
> 
> 
	Hi, Stephen,

	It seems, that it is not clear to the compiler, what you mean by
*argv[ii]. Note that argv is an array of pointers to char. When i am
in such a situation, i always use argv[ii][0], then, according to my
understanding, it can only mean one thing: the first character of the
text, pointed to by the address found in the ii-th element of array argv.
So, try the next line instead of your line 98:

   if (argv[ii][0] == '-') option_val = read_options;

Whatever read_options is. Should read_options be a function, then that
would possibly be the error. Using just the name of a function is not
wrong in C, but it will be interpreted as the address where that
function is located. As option_val is an integer, it is wrong to
squeeze an address in it (although it may fit). In that case the line
while be something like:

   if (argv[ii][0] == '-') option_val = read_options(&argv[ii][1]);

The function read_options must in this case know, what text the option
is made of.


Good luck!


--
*****************************************************************************
* Kees de Boer, Laan van Kanaan 93, NL-1944 RN  BEVERWIJK, Netherlands      *
* tel: (0251) 247 560, E-mail: boerkees@xs4all.nl                           *
* URL: http://www.xs4all.nl/~boerkees                                       *
*****************************************************************************
Re: Coding problem
#2392
Author: Tanmoy Bhattacharya
Date: Wed, 27 Mar 1996 00:59
23 lines
1654 bytes
In article <4iepuv$aiv@solutions.solon.com>
<snip>
b: 	It seems, that it is not clear to the compiler, what you mean by
b: *argv[ii]. Note that argv is an array of pointers to char. When i am
b: in such a situation, i always use argv[ii][0], then, according to my
b: understanding, it can only mean one thing: the first character of the
b: text, pointed to by the address found in the ii-th element of array argv.

I hope every C compiler has better understanding than that! *argv[ii]
is exactly the same as argv[ii][0] in all contexts where either is
valid. It is true that technically the latter involves adding a zero
to the pointer before dereferencing, but whenever dereferencing is
allowed, so is adding a zero.

Cheers
Tanmoy
--
tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads