Mail Archives: djgpp/1998/02/22/20:15:35
Message-ID: | <34F0C920.EA8645BF@csun.edu>
|
Date: | Sun, 22 Feb 1998 16:56:00 -0800
|
From: | Ryan Bright <rmb56313 AT csun DOT edu>
|
Reply-To: | rmb56313 AT csun DOT edu
|
MIME-Version: | 1.0
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: How do i make a C program recieve command line switches.
|
References: | <01bd3ff3$d01ce7c0$0100a8c0 AT comp1>
|
NNTP-Posting-Host: | s253n030.csun.edu
|
Organization: | California State University, Northridge
|
Lines: | 28
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Rushworth P-12 wrote:
>
> I'm Trying to make an alternative to DIR that can exclude file and list
> only certain types of files how do a make the program recieve command line
> parameters.?
First off, have you typed DIR /? lately? It's a pretty versatile little
command.
To accept command-line params, declare your main function like this :
int main(int argc, char *argv[]) {
...
}
Now, argc will contain the number of command line paramaters (btw, the
program name counts as one; ie: for "prognam -?", argc = 2) and *argv[]
will contain the actual parameters. Here's a quick example (untested) :
#include <stdio.h>
int main(int argc, char *argv[]) {
int k = argc;
while (k--) printf("%s\n", argv[k]);
return 0;
}
It should print out all the command line arguments in descending order.
-Ryan
- Raw text -