🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2305

Re: Coding problem

#2305
From: 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                                       *
*****************************************************************************
Technical Details
Message-ID: <4iepuv$aiv@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: boerkees@xs1.xs4all.nl (boerkees)
Newsgroups: comp.lang.c.moderated
Subject: Re: Coding problem
Date: 16 Mar 1996 10:23:59 -0600
Organization: XS4ALL Internet
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4iepuv$aiv@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com
X-Newsreader: TIN [version 1.2 PL2]