Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ main(3C) — DG/UX R4.11

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exec(2)

wait(2)

wait3(2)

exit(3C)

getenv(3C)



main(3C)                          SDK R4.11                         main(3C)


NAME
       main - enter a C main program

SYNOPSIS
       main ([argc, argv, envp])
       int argc;
       char *argv[];
       char *envp[];
       {
       .
       .
       .
       }

   where:
       argc   is optional and is the number of arguments, including the
              program name, with which you invoke the C program.
       argv   is optional and is a pointer to an array of pointers to
              strings; argv[0] is the name you invoked the program with;
              argv[1] is the first argument on the command line after the
              program name; argv[argc] is a null pointer.
       envp   is optional and is a pointer to an array of pointers to
              strings, each of which is a separate environment variable of
              the form NAME = VALUE.  The getenv function (described earlier
              in this chapter) accesses this list of environment variables.
              The DG/UX system routines execle and execve can change the
              environment of the new process if it is a C program.

DESCRIPTION
       Every C program has at least one function: the main function.  This
       function provides a place for the program to begin execution; the
       main function must be present to initiate a C program.  The runtime
       initializer calls main and returns to the system when main returns.

       Since argv[0] is the program name, the initial value of argc is
       always at least 1. If you want to manipulate the argv character
       arrays as something other than strings, you must make explicit use of
       such functions as atof or atoi.

       If your program does not process command line arguments, begin the
       function with the following:

       main()

EXAMPLE
       /* Program test for the main() function */

       int  i = 1;

       main(argc, argv, envp)
       int     argc;
       char   *argv[];
       char   *envp[];
       {
           printf("You called the program %s.\n", argv[0]);
           while (i < argc) {
               printf("Argument %d for this run is %s.\n",
               i, argv[i]);
               i++;
           }
       }

       A call to the program test with arguments alpha, beta, and gamma
       generates the output

       You called the program test.
       Argument 1 for this run is alpha.
       Argument 2 for this run is beta.
       Argument 3 for this run is gamma.

RETURNS
       The main function's return value is used as an argument to the exit
       function.  The value 0 typically means no errors occurred, and a non-
       zero value indicates an error condition.  The wait function can
       retrieve this value.

SEE ALSO
       exec(2), wait(2), wait3(2), exit(3C), getenv(3C).


Licensed material--property of copyright holder(s)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026