🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3061

Re: A small programming challenge.

#3061
From: Trent Tobler
Date: Mon, 20 May 1991 19:53
40 lines
1967 bytes
From article <1499@loki.une.oz.au>, by kevin@loki.une.oz.au (Kevin Pollard):
> I have written some code to accept command line parameters and apply
> meaningful parameters - but I feel it is an interesting problem which
> must have some neat solutions.
> 
> The task is:
> 	allow up to 4 parameters to be entered on the command line
> 	(that is, progname [ p1 [ p2 [ p3 [ p4 ] ] ] ] if you know what I mean) 
> 	The program is to accept the parameters. If the a parameter
> 	is missing then it is to default to the parameter is to 
> 	default to the one before it.
> 	(that is, if  progname x y z   is entered, then the 4th parameter
> 	 is to default to z)
> 	and so on down to the first parameter which is to have a hard
> 	coded default. If no parameters were entered then all parmeters
> 	would end up defaulting to this hard coded default.
> 
> 
> 
> Does anyone out there know of some neat ways of doing this.
> 
> This is really an algorithm problem, but since there is no algorithm
> newsgroup, and I program in C on an IBM-type machine, this would be
> a relevant newsgroup.

Are you sure this is not a homework assignment?  It looks so simple that
I hesitate to give the answer.  Perhaps the algorithem is what you want.  If
so here it is:

  assign default to hard_default.
  assign n to 0 (or 1 if that is the array base)
  repeat 4 times :
     if there is an argument then assign p[n] to it.
       otherwise, assign default to p[n].
     assign default to p[n]
     increment n

--

  Trent Tobler
Technical Details
Message-ID: <1991May20.195347.12231@unislc.uucp>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!uunet!viusys!uxui!unislc!ttobler
References: <1499@loki.une.oz.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!uunet!viusys!uxui!unislc!ttobler
From: ttobler@unislc.uucp (Trent Tobler)
Newsgroups: comp.std.c
Subject: Re: A small programming challenge.
Message-ID: <1991May20.195347.12231@unislc.uucp>
Date: 20 May 91 19:53:47 GMT
Article-I.D.: unislc.1991May20.195347.12231
References: <1499@loki.une.oz.au>
Organization: unisys
Lines: 40