How to call main function parameter in C program

Source: Internet
Author: User
Tags command line include

The main function provides a reference prototype such as:

int _tmain(int argc, _TCHAR* argv[])
{
for(int i=0;i<argc;i++)
 _tprintf(_T("%s\n"),argv[i]);
return 0;
}

或者如:
int main(int argc, char **argv)
{
}

Linux for:

#include "/usr/include/stdio.h"
int main(int argc, char **argv)
{
int i=0;
for(i=0;i<argc;i++)//不支持在for语句中嵌套定义
 printf("%s\n",argv[i]);
return 0;
}
>

The rationale is the same, ARGC represents the number of arguments (the numbers of strings separated by spaces), argv is a set of string arrays, passed in by the command line, Argv[0] is the file name for the command line itself, Argv[1 is the first argument, and so on.

In the first procedure above, output all command-line arguments sequentially (the first line output command itself).

Note: Although it is original, but the technical content is limited, but I learn some of the program design history records, if there are improper places welcome exchanges. This kind of article is not what I am good at, must not take my idea as the conclusion.

This article is from the "Tommy (Data Recovery)" blog, please be sure to keep this source http://zhangyu.blog.51cto.com/197148/153991

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.