Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Command-Line Arguments
◄Up► ◄Contents► ◄Index► ◄Back►
────────────────────────────────────────────────────────────────────────────
Keyword: main, argc, argv, envp
Syntax: main( int argc, char *argv[], char *envp[] )
{
<program-statements>
}
Summary: The main function is the name of the function that marks
the beginning and end of program execution. A C program
must have one function named main.
See also: _dos_findfirst, _dos_findnext, getenv, putenv, _searchenv
◄Expanding Wild-Card Arguments►
◄Parsing Command-Line Arguments►
◄Suppressing Command-Line Processing►
The main function can take the following three optional arguments,
traditionally called argc, argv, and envp (in that order):
Argument Description
argc An integer specifying how many arguments are passed
to the program from the command line. Since the
program name is considered an argument, argc is at
least one.
argv An array of null-terminated strings. It can be
declared as an array of pointers to char
(char *argv[]) or as a pointer to pointers to char
(char **argv). The first string (argv[0]) is the
program name, and each following string is an
argument passed to the program from the command
line. The last pointer (argv[argc]) is NULL.
envp A pointer to an array of environment strings. It
can be declared as an array of pointers to char
(char *envp[]) or as a pointer to pointers to char
(char **envp). The end of the array is indicated by
a NULL pointer.
-♦-