C Question now ....

Brad De Vries devriesbj
Mon May 17 11:48:13 PDT 2004


--- Ben Duncan <bns at meta3.net> wrote:
> Ok, now for my question of the day.
> After 18 years in UNIX and 8 in linux, started
> getting serious on
> developing my C skills. Most of revolves around
> Appgen stuff.
> 
> Anyway, I wrote a C program to tell me what kind of
> application an
> Appgen program is.  Program is called typeprog. To
> wit:
> 
> typeprog PDEF.OE07000
> 
> returns:
> 
> "Program PDEF.OE070000 is a Maint and uses OE-INVCE
> file."
> 
> Now, I would like to xpand that to use something
> like
> 
> "typeprog `ls PDEF.IV*`  "  or      " ls PDEF.IV |
> typeprog"
> 
> as well.
> 
> Now, I know argv[1] gives me the program name, but
> how do I go about
> xpanding that to use the latter style as well as the
> first and determine which
>   I have incoming and to walk the list given by the
> latter?
> 
> 
> I know I will probably have to put a while loop in
> it, but as for the
> rest, I am lost ...
> 
> -- 
> Ben Duncan

You're right about argv[1] being the value of the
first parameter and you can use that together with
argc for the number of parameters.  So a simple little
loop like:

for(i=1;i<=argc;i++) {
  do stuff with argv[i]
}

would process each parameter in order.

For the second example, you're processing the
filenames from stdin.  You simply treat stdin just
like a file and read the "file" to obtain the "data"

HTH,
Brad.

__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com


More information about the Linux-users mailing list