Main (argc,argv[])

Source: Internet
Author: User
Tags first string

Each C language program must have a function called main () as the starting point for the program to start. When executing a program, command-line arguments (command-line argument) (parsed by the shell) are supplied to the main () function by two arguments. The first argument, int argc, represents the number of command-line arguments. The second argument, Char *argv[], is an array of pointers to command-line arguments, each of which is a string that ends with a null character (null). The first string, that is, argv[0] points to, (usually) the name of the program. The list of pointers in argv ends with a null pointer (that is, ARGV[ARGC] is null).

Argv[0] contains the name of the calling program,

Using main (int argc,char *argv[]) = = Main (int argc,char **argv) Basic operation is the most basic step of Linux programming, under Windows is also exe out of the IDE to run the necessary skills, after the program was compiled successfully, Under CMD, use the parameter input to run the program and control the input of the parameters to test and run the program.

int ARGC represents the number of input parameters, the English full name argumentscount, is counted as a space, and the program name (*.exe) is the first parameter.

Char *argv[] Stores the contents of the parameter as an array of characters, the English full name arguments vector, argv[1] represents the program name.

The following program shows the use of ARGC and argv:

#include <stdio.h>int main (int argc, char * * argv) {    int i;    for (i=0; i < argc; i++)        printf ("Argument%d is%s./n", I, Argv[i]);    return 0;}

If the above code is compiled to Hello.exe, then run

Hello.exe a b c d E

Will get

Argument 0 is hello.exe.Argument 1 are a.argument 2 is b.argument 3 are c.argument 4 is d.argument 5 is E.

Run

Hello.exe lena.jpg

Will get

Argument 0 is hello.exe.Argument 1 is lena.jpg.
Method 2. Project--Properties--Configuration Properties--debug--command parameters, set command parameters can be passed in



Http://www.cnblogs.com/rainbow70626/p/5595454.html

Main (argc,argv[])

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.