Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!ncar!hsdndev!cmcl2!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.unix.questions Subject: Re: Expanding wildcard options to main() Message-ID: <15684@smoke.brl.mil> Date: 3 Apr 91 00:26:30 GMT References: <1991Apr1.194817.20469@fmrco> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 18 In article <1991Apr1.194817.20469@fmrco> harold@fmrco (Harold Naparst) writes: >How do you pass wildcard options to a program and get the >program to expand them like ls does. Example: suppose I >have two files called foo1 and foo2, and I want to run >myprog on them. How would I write myprog so that I could >just do this: > % myprog foo* You should have learned from your UNIX tutorial that wildcards are expanded by the shell (command language interpreter) before the commands are run, and the commands receive the expanded SET of arguments. Type "echo foo*" to see it in action (assuming that you do have files "foo1" and "foo2" present). Program arguments are passed to C programs as an array of string pointers as the second argument to the main() function, and to Bourne shell scripts as "dollar" variables: $1, $2, ... There is also an indication of the number of arguments. Any book on UNIX programming should explain how to parse arguments.