Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/m/main.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/m/main.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/m/main.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/m/main.html on line 8

main()

Program entry function

Synopsis:

int main( void );

int main( int argc, 
          const char *argv[] );

int main( int argc, 
          const char *argv[], 
          char *envp[] );

Arguments:

The arguments depend on which form of main() that you use.

argc
The number of entries in the argv array.
argv
An array of pointers to strings that contain the arguments to the program.
envp
An array of pointers to strings that define the environment for the program.

Description:

The main() function is supplied by the user and is where program execution begins. The command line to the program is broken into a sequence of tokens separated by blanks, and are passed to main() as an array of pointers to character strings in argv. The number of arguments found is passed in the parameter argc.

The argv[0] argument is a pointer to a character string containing the program name. The last element of the array pointed to by argv is NULL (argv[argc] is NULL). Arguments containing blanks can be passed to main() by enclosing them in quote characters (which are removed from that element in the argv vector). See your shell's documentation for details.

The envp argument points to an array of pointers to character strings that are the environment strings for the current process. This value is identical to the environ variable, which is defined in the <stdlib.h> header file.

Returns:

A value back to the calling program (usually the operating system).

Examples:

#include <stdio.h>
#include <stdlib.h>

int main( int argc, char **argv )
{
    int i;
    for( i = 0; i < argc; ++i ) {
        printf( "argv[%d] = %s\n", i, argv[i] );
    }
    
    return EXIT_SUCCESS;
}

produces the output:

argv[0] = ./mypgm
argv[1] = hhhhh
argv[2] = another arg

when the program mypgm is run from the shell:

$ ./mypgm hhhhh "another arg"

Classification:

ANSI, POSIX 1003.1

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

See also:

abort(), atexit(), _argc, _argv, _auxv, close(), execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), _exit(), exit(), getenv(), putenv(), sigaction(), signal(), spawn(), spawnl(), spawnle(), spawnlp(), spawnlpe(), spawnp(), spawnv(), spawnve(), spawnvp(), spawnvpe(), system(), wait(), waitpid()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/m/main.html on line 200

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/m/main.html on line 200